473,505 Members | 15,976 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to design such class

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?

Thank you very much!
Jul 22 '05 #1
4 1193

"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?

Thank you very much!


I don't see anything wrong with the design you have, what do you think is
wrong with it? It's pretty hard to why it should be any different given your
description.

I think the emphasis of the question is quite wrong, maybe you've
misunderstood what you've been asked. Obviously EngineClass etc. could
change in the future but it is not the responsibility of CarClass to use
EngineClass in some special way just in case it might change. That would not
make EngineClass very user friendly, and would mean extra work for every
class that used EngineClass. Instead it should be EngineClass that is
designed in such a way so that other classes can use it without worrying
about future changes to it implementation. This is a basic goal of object
orientated design.

john
Jul 22 '05 #2

"gigal" <gi*******@168.com> schrieb im Newsbeitrag
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?

That depends very much on what you want to achieve. In principle the example
you gave is the straight forward approach and there is nothing wrong with
that, however there are of course different ways. One might think for
example of introducing a vector of additional features which holds some
customer specific "extra equipment" like GPS, TV, mobile phone or whatever
which is not included in the standard version of the car.
Another way would be to use a decorator pattern, though I guess that might
be too much for a simple thing like this.
Thank you very much!

HTH
Chris
Jul 22 '05 #3
"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
Jul 22 '05 #4
gigal wrote:

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?


Another thing: if CarClass gets even just moderately big and complex,
you may notice a number of big adavantages in arranging its parts into
hierarchies:

class CarClass {
Body b;
Mechanics m;
Conveneience c;
//...
};

class Mechanics {
Engine e;
Transmission t;
//...
};
class Convenience {
GPSClass gps;
CDPlayerClass cd;
//...
};

At a top level, each component is a Facade to its sub-components, and
so on recursively. Each facade provides a single interface to a higher-
level system; it hides the dependencies and implementation details of
its sub-components.
The "right" way to structure this depends on the aspect that you are
modelling (e.g. whether CarClass is used to build a functional model,
parts inventory, or an informational pamphlet).

Denis
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3118
by: Omer van Kloeten | last post by:
The Top Level Design: The class Base is a factory class with a twist. It uses the Assembly/Type classes to extract all types that inherit from it and add them to the list of types that inherit...
4
1973
by: Ian Giblin | last post by:
I am an experienced C programmer, learning C++ by writinging a mathematical toolkit in the framework of a script interpreter. I am posting here to ask for advice (or references) on the object...
2
1840
by: Matthew Hood | last post by:
My company has expressed a desire to convert an existing MS Access application to a full VB.NET application. My experience is with VB6 so I want to ask a few questions and get some input on the...
1
6319
by: Nogusta123 | last post by:
Hi, I have had a lot of problems getting web pages, master pages and content pages to render in VS2005 design view the same as they would in Internet Explorer. I did a lot of looking on the...
6
2058
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
11
18070
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
6
2121
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
9
2806
by: Grizlyk | last post by:
Somebody have offered std colors to C++ in the msg here: http://groups.google.com/group/comp.lang.c++/browse_frm/thread/2e5bb3d36ece543b/1acf6cd7e3ebdbcd#1acf6cd7e3ebdbcd The main objection to...
8
2207
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address,...
5
1721
by: pgrazaitis | last post by:
I cant seem to get my head wrapped around this issue, I have myself so twisted now there maybe no issue! Ok so I designed a class X that has a few members, and for arguments sake one of the...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.