473,395 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

the best class design

Hi,

my question is about OO design. imagine we have 2 classes with some common
members and some different members. which one is better and why:

1) design class A completely and B as a drived from A with the different
members.

2) design a super class with common members then design class A and B drived
from this super class with their different members.
Nov 16 '05 #1
3 1481
1) design class A completely and B as a drived from A with the different
members.

2) design a super class with common members then design class A and B drived
from this super class with their different members.


Inheritance should model 'isa' relationships. Is B a specialized type of
A? If not, then it should not inherit from it. It is ok for CDog and
CCat to both inherit from CAnimal, since both dogs and cats are kinds of
animals. But a dog is not a cat, so CDog should not inherit from CCat.

A common mistake is to use inheritance for the sake of code reuse. This
can lead to the wrong types of relationships in your class hierarchy.

H^2


Nov 16 '05 #2
1) design class A completely and B as a drived from A with the different
members.

2) design a super class with common members then design class A and B drived
from this super class with their different members.


Inheritance should model 'isa' relationships. Is B a specialized type of
A? If not, then it should not inherit from it. It is ok for CDog and
CCat to both inherit from CAnimal, since both dogs and cats are kinds of
animals. But a dog is not a cat, so CDog should not inherit from CCat.

A common mistake is to use inheritance for the sake of code reuse. This
can lead to the wrong types of relationships in your class hierarchy.

H^2


Nov 16 '05 #3
Are the common members named the same but do they behave differently, or are
they the same? If A has members that aren't in B and B has members that
aren't in A, you can eliminate #1.

If they have members that are identical, I would derive them both from a
common parent class. So that all common code would exist in one place.

If you need to use polymorphism and the have members that behave
differently, I would derive them from an abstract superclass.

If you don't need polymorphism and their common members all behave
differently, I would just code them separately. Since there would be no
advantage to using inheritance.

"Mojtaba Faridzad" <mf*******@hotmail.com> wrote in message
news:Ot*************@TK2MSFTNGP10.phx.gbl...
Hi,

my question is about OO design. imagine we have 2 classes with some common
members and some different members. which one is better and why:

1) design class A completely and B as a drived from A with the different
members.

2) design a super class with common members then design class A and B drived from this super class with their different members.

Nov 16 '05 #4

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

Similar topics

16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
3
by: Ares Lagae | last post by:
Suppose one is writing a library behavior the classes A1, A2 and A3, which share some common behavior. Some applications will only use one of the classes, while other applications will use all of...
1
by: Herve MAILLARD | last post by:
Hi, I have to write a software doing the following : - Load a file (containing data) Data will be display in a Treeview and are typed as following Equipement Bloc Tag It could have for each...
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
5
by: wrecker | last post by:
Hi all, I have a few common methods that I need to use at different points in my web application. I'm wondering where the best place would be to put these? I think that I have three options. ...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
9
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private...
4
by: =?Utf-8?B?bW9mbGFoZXJ0eQ==?= | last post by:
In VB6, we created a number of ActiveX DLLs that all shared a similar interface. The main application would load these in dynamically (late-bound.) This worked well for our situation because we...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.