C++:关于OOP的key ideas之一的data abstraction

2014.4.13

参考材料:C++ Primer 5th edition (Chap 7, Chap 15)

1. Data abstraction是一项programming/design technique。通过separation of interface and implementation得以实现data abstraction.

(附加我的理解:要区分开C++中class和data abstraction的概念)

{

  论点一:C++设定class的目的不是为了实现data abstraction,而是另有目的。

(chap 7: class defines our own types. By defining our own types that mirror concepts in the problems we are trying to solve, we can make our programs easier to write, debug, and modify.)

也即,C++设定class的目的是为了we can make our programs easier to write, debug, and modify.(这一点我还不是十分理解,即class怎么样让我们更容易写program,更容易调试和改正错误?)


  论点二:在class的具体实现上,C++支持设计者用data abstraction和encapsulation的思路来实现class。

   (chap 7: The fundamental ideas behind classes are data abstractions and encapsulation)

在下面具体说明C++如何支持data abstraction和encapsulation的。


}


2. C++在class中支持encapsulation的方法就是public和private。让class的user只能使用public,而不能使用private。(Encapsulation enforces the separation of a class' interface and implementation, 重点在“enforce”上)

  进一步说,你写得class如果决定不采用public和private,就是选择不采用encapsulation的思路。也就是说,class不一定体现了encapsulation,class也有可能没有体现encapsulation。


3. C++在class中是通过什么手段实现的data abstraction呢?我暂时还没想到。

  data abstraction是要分离interface和implementation。那么class的interface和implementation如下:

"The interface of class consists of the operations that users of the class can execute."

"The implementation includes the class' data members, the bodies ofthe functions that constitute the interface, and any functions needed to define the class that are not intended for general use."


4.  (是这样吗?)C++不仅在class中支持了data abstraction和encapsulation,在别的地方也体现了这个思路。

如,可以将函数的声明和定义分开是不是就是C++支持data abstraction在function方面的方法呢?


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值