< previous page page_934 next page >

Page 934
(text box continued from previous page)
ject is not useful after all. Or we might decide to add or eliminate operations on a particular object.
There is always more than one way to solve a problem. Iterating and reiterating through the design phase leads to insights that produce a better solution.

Implementing the Design
In OOD, when we first identify an object, it is an abstract object. We do not immediately choose an exact data representation for that object. Similarly, the operations on objects begin as abstract operations, because there is no initial attempt to provide algorithms for these operations.
Eventually, we have to implement the objects and operations. For each abstract object, we must
choose a suitable data representation.
create algorithms for the abstract operations.
To select a data representation for an object, the C++ programmer has three options:
1. Use a built-in data type.
2. Use an existing ADT.
3. Create a new ADT.
For a given object, a good rule of thumb is to consider these three options in the order listed. A built-in type is the most straightforward to use and understand, and operations on these types are already defined by the language. If a built-in type is not adequate to represent an object, you should survey available ADTs in a class library (either the system's or your own) to see if any are a good match for the abstract object. If no suitable ADT exists, you must design and implement a new ADT to represent the object.
Fortunately, even if you must resort to option 3, the mechanisms of inheritance and composition allow you to combine options 2 and 3. When we needed an ExtTime class earlier in the chapter, we used inheritance to build on an existing Time class. And when we created a TimeCard class, we used composition to include a Time object in the private data.
In addition to choosing a data representation for the abstract object, we must implement the abstract operations. With OOD, the algorithms that implement the abstract operations are often short and straightforward. We have seen numerous examples in this chapter and Chapter 15 in which the code for ADT operations is only a few lines long. But this is not always the case. If an operation is extremely complex, it may be best to treat the operation as a new problem and use top-down design on the control flow. In this situation, it is appropriate to apply both top-down and object-oriented method-

 
< previous page page_934 next page >