The GNU C++ library
The GNU C++ library
复制标题
DOI:
--
复制
发表时间:
1996-05
影响因子:
3.8
通讯作者:
D. Lea
中科院分区:
文献类型:
--
作者:
D. Lea
Data Types and Values While both may be described as C++ classes, there is a big di erence between, say, a Complex number and, say, a BankAccount. For example, there is a large, well-established mathematical theory of complex numbers, but essentially none for bank accounts. One consequence is that it is simply much easier to develop a Complex class containing features that one may be reasonably certain will makes sense across a wide range of applications. This is much less true of any BankAccount class one could construct. A more important distinction underlies the resulting design di erences. The \theory" of complex numbers revolves around the properties of complex values, not objects. Mathematical approaches typically abstract over the actual identities of objects possessing (Re, Im) attributes, and just deal with the values themselves { the complex quantity (2.4, 17.17) remains the same regardless of which or how many objects report this quantity as real(), and imag() attribute functions. By design, many operations don't care about the objects, and just deal with the quantities. However, this would be a losing attitude for a class like BankAccount. For example, even when we happen to both have the same bank balance, the fact that a particular identi able BankAccount instance belongs to you and not me is an obvious but critical design issue. These di erences result in di erent styles, approaches, and plans of attack for designing the associated classes and utilities. For example, while it is perfectly sensible to write a \constructive" function that accepts two complex numbers and returns a third representing their sum, there is hardly ever a reason to create a function that accepts two bank accounts and returns a third representing (among other things) the sum of their balances. Instead, the BankAccount class contains methods such as withdraw, transfer, and so on that mutate the states of particular objects. Libg++ contains substantially more components like Complex than those like BankAccount. Many classes maintain \value semantics", in a manner more similar to classic ADT approaches than to classic OO approaches.