- kinds of Classes
The C++ programming Language
The C++ class is a programming language construct that serves a variety of design needs. In fact, Ifind that the solution to most knotty design problems involves the introduction of a new class torepresent some notion that had been left implicit in the previous draft design (and aybe the elimination of other classes). The great variety of roles that a class can play leads to a variety of kinds of classes that are specialized to serve a particular need well. In this chapter, a few archetypical kinds of classes are described, together with their inherent strengths and weaknesses:
These‘kinds of classes’ are design notions and not language constructs. The unattained, and probably unattainable, ideal is to have a minimal set of simple and orthogonal kinds of classes from which all wellbehaved and useful classes could be constructed. It is important to note that each of these kinds of classes has a place in design and none is inherently better than the others for all uses.Much confusion in discussions of design and programming comes from people trying to use only one or two kinds of classes exclusively. This is usually done in the name of simplicity, yet it leads to contorted and unnatural uses of the favored kinds of classes.
The description here emphasizes the pure forms of these kinds of classes. Naturally, hybridforms can also be used. However, a hybrid ought to appear as the result of a design decision based on an evaluation of the engineering tradeoffs and not a result of some misguided attempt to avoid making decisions. ‘‘Delaying decisions’’ is too often a euphemism for ‘‘avoiding thinking.’’ Novice designers will usually do best by staying away from hybrids and also by following the style of an existing component with properties that resemble the desired properties for the new component. Only experienced programmers should attempt to write a generalpurpose component or library,and every library designer should be ‘‘condemned’’ to use, document, and support his or her creation for some years. Also, please note §23.5.1.
(2) Concrete Types[role.concrete]
Classes such as vector are concrete in the sense that each is the representation of a relatively simple concept with all the operations essential for the support of that concept. Also, each has a onetoone
Correspondence between its interface and an implementation and none are intended as a base for derivation. Typically, concrete types are not fitted into a hierarchy of related classes. Each concrete type can be understood in isolation with minimal reference to other classes. If a concrete type is implemented well, programs using it are comparable in size and speed to programs a user would write using a handcrafted and specialized version of the concept. Similarly, if the implementation changes significantly the interface is usually modified to reflect the change. In all of this, a concrete type resembles a builtin type.
- 上一篇：Auditing of the fire wall
- 下一篇：Working with Databases