473,809 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Inheritance -- clarification needed ?

Hi,

Have this following hierarchy which am implementing for a networking
program. The base class 'ASocket' is the base class from which
'AListener' and 'ATalker' inherit . None of the functions in the
derived classes would override functions from the base class. The
derived classes would extend the base class. A couple of doubts :

1. Should the functions in the base class be declared virtual ?

2. Is this a good way to go about things or should one make ASocket an
abstract base class ? ( thinking in terms of interface based
programming )

3. The Inheritance topic in C++ FAQ slightly confuses me .. It talks a
lot about protected inheritance .. should that be a concern for such a
situation.

Thanks in advance.

Apr 8 '06 #1
4 1476
* vivekian:

Have this following hierarchy which am implementing for a networking
program. The base class 'ASocket' is the base class from which
'AListener' and 'ATalker' inherit . None of the functions in the
derived classes would override functions from the base class. The
derived classes would extend the base class. A couple of doubts :

1. Should the functions in the base class be declared virtual ?
When you're not overriding anything there's no apparent reason.

But are you sure you're not overriding anything?

E.g., if you're deleting an object via an ASocket* pointer, then you
should be overriding the destructor, which should then be virtual.

2. Is this a good way to go about things or should one make ASocket an
abstract base class ? ( thinking in terms of interface based
programming )
AFAICS you don't provide enough information to answer that.

3. The Inheritance topic in C++ FAQ slightly confuses me .. It talks a
lot about protected inheritance .. should that be a concern for such a
situation.


AFAICS you don't provide enough information to answer that.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 8 '06 #2

Alf P. Steinbach wrote:
2. Is this a good way to go about things or should one make ASocket an
abstract base class ? ( thinking in terms of interface based
programming )


AFAICS you don't provide enough information to answer that.

3. The Inheritance topic in C++ FAQ slightly confuses me .. It talks a
lot about protected inheritance .. should that be a concern for such a
situation.


AFAICS you don't provide enough information to answer that.


okay, my bad.
ASocket has the following methods -- openSocket () , closeSocket () ,
bind() which are common to both the derived classes and would remain
the same for both of them. AListener would have specific methods to
listen to incoming UDP packets and ATalker would have the ability to
broadcast such packets.

Though this is probably a one time coding effort, but was thinking if
lets say some time later the class needs to add TCP functionality , so
then requirements would change, the openSocket and closeSocket function
would require different arguments. In what way should my thought
process and design be to forsee future extensibility ? ( Thinking in
terms of direction inversion principle ) and thus asking about abstract
class ?

Also the Atalker and Alistener class would be used by other classes as
in a composition relationship ? This is where the c++ FAQ confuses me
e.g. "I've been told to never use protected data, and instead to always
use private data with protected access functions. Is that a good
rule?". Am not sure if all the FAQ are relevant here ?

thanks again .

Apr 8 '06 #3

vivekian wrote:
In what way should my thought
process and design be to forsee future extensibility ?


It shouldn't. You should design and implement what you need in the
most abstract way you can think of with the least amount of
dependencies between modules. That is all. Let the future establish
itself. Reasons:

1) you spend all your time in analysis paralisys and never get anything
done if you try to think of every possibly future need.

2) you can't think of every possibly future need so why try?

3) Just following some guidelines and avoiding pitfalls makes it easy
to make changes later.

All you need to do is prepare yourself for the possibility of having to
make changes to the code base by keeping the smells to a minimum.
Learn how to refactor...reco gnize bad code and learn how to turn it
into good code and how to take good code and change it to match new
needs.

With that in mind...inherita nce is the strongest binding you can create
between two modules short of friendship. Avoid when not needed.

Yes, I got all that from books but it also applies very well in the
real world.

Apr 8 '06 #4

Noah Roberts wrote:
vivekian wrote:
In what way should my thought
process and design be to forsee future extensibility ?
It shouldn't. You should design and implement what you need in the
most abstract way you can think of with the least amount of
dependencies between modules. That is all. Let the future establish
itself.


Yes , makes sense. So does that translate into using abstract classes
to minimize dependencies. ? e.g. in my case .. there would be an
abstract base class called ASocket from which both UDPSocket and
TCPSocket could derive ?
With that in mind...inherita nce is the strongest binding you can create
between two modules short of friendship. Avoid when not needed.


This is the part which confuses me most. When do i use inheritance ?
while coding when there are two classes which share common
functionality it makes so much sense to put this common functionality
in a base class and then specialize with derived classes. But then
everyone says 'use inheritance with caution' and makes me think twice..
so lets say in the above case , when ATalker and AListener have
functions in common , is it not right for them to derive from ASocket ?

Apr 8 '06 #5

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

Similar topics

4
12822
by: Dave Theese | last post by:
Hello all, The example below demonstrates proper conformance to the C++ standard. However, I'm having a hard time getting my brain around which language rules make this proper... The error below *should* happen, but my question to the community is *why* does it happen? Any answer will be appreciated, but a section and paragraph number from the C++ Standard would be especially appreciated.
19
3198
by: Mike Tyka | last post by:
Hello community, i'm fairly new to using the STL but i've been experimenting a bit with it. I tried to derive a new class say MyString from string like so: class MyString: public string{ public: MyString(){} };
6
4892
by: Martin | last post by:
Hi, Suppose I have 3 interfaces : IStats IEngine ICreateCar each derives from IUnknown
14
12927
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at all obvious in VBA which lacks inheritance. I'm trying the explanation again now. I often find cases where a limited form of inheritance would eliminate duplication my code that seems impossible to eliminate otherwise. I'm getting very...
8
1849
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I need to build multiple mixed mode dll's used by a consumer application, do I have to implement multiple ManagedWrapper's (each embedded in indiviudal DLL project) and call all of them in my consumer application?
3
2573
by: Hazz | last post by:
I am just beginning to design a Treeview display (winforms) for wine regions. Problem. Some wine growing regions belong to two counties. Eg. Carneros is in both Napa and Sonoma Counties. Although most nodes will have only one parent, a few will have two parents. The Treeview which seems to me to lend itself to the Windows Explorer type of app could not possibly show one file as a leaf belonging to two different parent folders. You either...
60
4952
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
23
4618
by: Dave Rahardja | last post by:
Since C++ is missing the "interface" concept present in Java, I've been using the following pattern to simulate its behavior: class Interface0 { public: virtual void fn0() = 0; };
3
1587
by: Jam | last post by:
Hello All, Your comment is needed on following subject,i define the Class and Inheritance as following,what do you think? Class: Class is a set of objects which shares common states and behaviors,Class can contain subclasses. Inheritance: if two classes are having two common states and behaviors or if a class is derived from another class it is called Inheritance, All's comment is needed,is this defination ok or something more should
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.