Re: How to hide implementation details?
Immortal Nephi <Immortal_Nephi@hotmail.com> wrote:
I want to create an interface of a door. The client is able to see
the implementation behind the interface because inheritance is
present. The code is stored in the header. How do I hide the
implementation?
A door is an abstraction of a particular arrangement of a rectangular
piece of material with hinges and a doorknob. It has four routines of
Open(), Close(), isOpened(), and isClosed().
And the doorknob is in turn an abstraction of a particular formation
of brass, nickel, iron, or steel. It has four routine of Lock(),
Unlock(), IsLocked(), and IsUnlocked().
And also, Color_Knob is in turn an abstraction of some colors.
How do I put three objects of Door, Knob, and Color_Knob together
into a function or another class. Is it the way how design looks
good?
The inheritance does not make any sense, but it should be
composition. Open() and Close() belongs to Door and they have no
reasons to be inherited into doorknob class nor color_knob class.
Also, Lock() and Unlock() belongs to doorknob class and should not be
inherited into color_knob.
Should knob_door and color_knob objects be created into memory and
place them in Door class like composition?
I'm not entirely sure that any of these classes make sense, but I'll try
to work with them...
Obviously a Knob is not a Door, but a colored knob is a knob. How are
real doors assembled? There is your hint. A Door Builder attaches a knob
and hinges onto the door, then he hangs it (or a Door Hanger hangs is,)
so that others can use it. When people lock a door, they do just that;
the knob is no longer a separate object, it is part of the door.
Some things to think about.