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方面的方法呢?


C++:关于OOP的key ideas之一的data abstraction,布布扣,bubuko.com

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

上一篇:从一个案例看mysqldump的复制选项


下一篇:Python多进程编程(一):初探