< previous page page_388 next page >

Page 388
Designing the Interfaces
It is important, at this stage of designing your product, to avoid being concerned with implementation. You want to focus all your energies on designing a clean interface among the classes, and then delineating what data and methods each class will need.
It is often a good idea to have a solid understanding of the base classes before trying to design the more derived classes, so you decide to focus on pObject, pStored and pWired.
The root class, pObject, will only have those data and methods that are common to everything on your system. Perhaps every object should have a unique identification number. You could create pID (PostMaster ID) and make that a member of pObject; but first you must ask yourself, Does any object that is not stored and not wired need such a number? That begs the question, Are there any objects that are not stored, but that are part of this hierarchy?
If there are no such objects, you might want to consider collapsing pObject and pStored into one class; after all, if all objects are stored, what is the point of the differentiation? Thinking this through, you realize that there may be some objects, such as address objects, that it would be beneficial to derive from pObject but that will never be stored on their own; if they are stored it will be as part of some other object.
This tells you that, for now, having a separate pObject class would be useful. You can imagine that there will be an address book that would be a collection of pAddress objects, and while no pAddress will ever be stored on its own, there would be utility in having each one have its own unique identification number. You tentatively assign pID to pObject; that means that pObject, at a minimum, will look like this:
class pObject
{
public:
   pObject();
   ~pObject();
   pID GetID()const;
   void SetID();
private:
   pID itsID;
}
There are a number of things to note about this class declaration. First, this class is not declared to derive from any other; this is your root class. Second, there is no attempt to show implementation, even for methods such as GetID() that are likely to have inline implementation when you are done.

 
< previous page page_388 next page >

If you like this book, buy it!