"gigal" <gi*******@168.com> wrote in message news:<N0********************@bgtnsc05-news.ops.worldnet.att.net>...
Currently, the class is defined as,
Class CarClass
{
EngineClass e;
SeatClass s[5];
CDPlayerClass cd;
...
};
In the future, a new member of class GPSClass type could be added for
example. EngineClass, SeatClass, and CDPlayerClass could change their
implementation of operations.
How to design CarClass?
Well, you did the correct thing by realizing that some things are more
likely to change than others, and you should indeed design for that. One
of the most important things to realize is what can change after
creation, and what's fixed. Of course, this is restricted to your
model. If you don't model recycling the steel in the doors for a
new engine, things are a lot easier.
Now, let's take your GPS class. Is that only added when the car is
built? Or can it be added later? That is an important distinction.
In the first case, you can create a new model car, with GPS. In
the latter case, you keep the single model but you add a mounting
point.
In C++ terms, the first solution is to create a class CarWithGPS,
the second solution is to add a GPS* to class Car. This pointer
would be == 0 until the GPS is mounted.
The second question is easier. Just keep the implementations
of these classes private, so that Car only relies on their
public interface.
Regards,
Michiel Salters