星期三, 5月 16, 2007

ADT - Abstract Data Type

受到 C# 的薰陶,一時間忘了 ADT 另一層的函意。今天在《Fundamentals of Data Structure in C++》中看到一段話:



The specification, which must be contained inside the public portion of the class definition of the ADT, consists of the names of every public member function, the type of its arguments, and the type of its result (This information about a function is known as its function prototype). There should also be a description of the function does, which does not refer to the internal representation or implementation details. This requirement is quite important because it implies that an abstract data type is implementation-independent.


一個完整的 ADT ,不僅要符合 Data abstraction 及 Encapsulation;更重要的是,它必須與實作無關。

ADT 著重於形態的抽象概念,而不是如何實踐此概念,因此 ADT 每一個 member function,只需說明此 function 能做什麼、該做什麼,而不必明定此 function 該如何做。

譬如說,一個 bignumber ADT 包含 add 此 member function。設計者只管以註解說明它的功用(對兩個 bignumber object 做相加),至於如何相加,相加後如何維護,皆與設計者無關。這些實作上的細節,是為實踐這些抽象概念的 programmer 才需關注的。

總之,ADT 是一種概念的陳述、一種規格的規範。它提供下一層設計者一些概念、一些介面標準,有助於設計者完成此 Type。但 ADT 絕不必提供任何實作上的資訊,就好像某 ADT 的使用者,絕不必了解它如何被實作出,只管此 ADT 代表什麼概念、提供了哪些功能。

沒有留言: