473,387 Members | 1,476 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,387 software developers and data experts.

OO system design question

I am writing a communications library, and have several classes in my
project. The "main" class (BaseEngine) is responsible for setting up the
low level comms machinery (queues, sockets, ports etc). I have chosen a
singleton pattern design for this class, because only one such object is
equired, to provide shared access to the underlying comms plumbing.

The other remaining classes all do little 'speacialized' jobs - e.g
sending heartbeat mesages, maintaining topics and subscribers,
forwarding messages etc, etc. They all require BaseEngine, to get their
work done.

Currently, I have designed the system so that the other classes have a
"uses-a" relationship with BaseEngine. The implementation is that I have
a private static variable of type BaseEngine in each of these classes.
My question is that is a "good" design?. Could I simply have allowed the
other classes to subclass (i.e. inherit from) BaseEngine?

Is one approach better than the other? - if yes, what are the pros and
cons on either method?.

Mar 12 '06 #1
3 1824
On Sun, 12 Mar 2006 11:16:19 +0000 (UTC), Bart Simpson
<ea*********@springfield.com> wrote:
I am writing a communications library, and have several classes in my
project. The "main" class (BaseEngine) is responsible for setting up the
low level comms machinery (queues, sockets, ports etc). I have chosen a
singleton pattern design for this class, because only one such object is
equired, to provide shared access to the underlying comms plumbing.

The other remaining classes all do little 'speacialized' jobs - e.g
sending heartbeat mesages, maintaining topics and subscribers,
forwarding messages etc, etc. They all require BaseEngine, to get their
work done.

Currently, I have designed the system so that the other classes have a
"uses-a" relationship with BaseEngine. The implementation is that I have
a private static variable of type BaseEngine in each of these classes.
My question is that is a "good" design?. Could I simply have allowed the
other classes to subclass (i.e. inherit from) BaseEngine?

Is one approach better than the other? - if yes, what are the pros and
cons on either method?.


If each class has a private static BaseEngine member as an object,
then you don't have a singleton because each class would have its own
instance of a different BaseEngine. Inheriting BaseEngine wouldn't
solve the problem for the same reason.

If BaseEngine is to be a true singleton, then you should be sharing a
pointer or reference to it, and not an object.

--
Bob Hairgrove
No**********@Home.com
Mar 12 '06 #2
Bart Simpson wrote:
I am writing a communications library, and have several classes in my
project. The "main" class (BaseEngine) is responsible for setting up the
low level comms machinery (queues, sockets, ports etc). I have chosen a
singleton pattern design for this class, because only one such object is
equired, to provide shared access to the underlying comms plumbing.

The other remaining classes all do little 'speacialized' jobs - e.g
sending heartbeat mesages, maintaining topics and subscribers,
forwarding messages etc, etc. They all require BaseEngine, to get their
work done.

Currently, I have designed the system so that the other classes have a
"uses-a" relationship with BaseEngine. The implementation is that I have
a private static variable of type BaseEngine in each of these classes.
My question is that is a "good" design?. Could I simply have allowed the
other classes to subclass (i.e. inherit from) BaseEngine?
Encapsulation (as you have it) is preferable to inheritance, unless you
have an "is substitutable for".
Is one approach better than the other? - if yes, what are the pros and
cons on either method?.


This is a FAQ, I believe:
http://www.parashift.com/c++-faq-lit....html#faq-24.2

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Mar 12 '06 #3


Bob Hairgrove wrote:
On Sun, 12 Mar 2006 11:16:19 +0000 (UTC), Bart Simpson
<ea*********@springfield.com> wrote:

I am writing a communications library, and have several classes in my
project. The "main" class (BaseEngine) is responsible for setting up the
low level comms machinery (queues, sockets, ports etc). I have chosen a
singleton pattern design for this class, because only one such object is
equired, to provide shared access to the underlying comms plumbing.

The other remaining classes all do little 'speacialized' jobs - e.g
sending heartbeat mesages, maintaining topics and subscribers,
forwarding messages etc, etc. They all require BaseEngine, to get their
work done.

Currently, I have designed the system so that the other classes have a
"uses-a" relationship with BaseEngine. The implementation is that I have
a private static variable of type BaseEngine in each of these classes.
My question is that is a "good" design?. Could I simply have allowed the
other classes to subclass (i.e. inherit from) BaseEngine?

Is one approach better than the other? - if yes, what are the pros and
cons on either method?.

If each class has a private static BaseEngine member as an object,
then you don't have a singleton because each class would have its own
instance of a different BaseEngine. Inheriting BaseEngine wouldn't
solve the problem for the same reason.

If BaseEngine is to be a true singleton, then you should be sharing a
pointer or reference to it, and not an object.

--
Bob Hairgrove
No**********@Home.com


thanks for the correction Bob (my Bad), the other classes hold a static
reference to BaseEngine (not the actual object as I had typed earlier)

Mar 12 '06 #4

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

Similar topics

5
by: DFS | last post by:
I've written several survey systems in which the majority of the questions have the same or similar responses (Yes/No, True/False, scale of 1 - 5, etc). But this latest survey system I'm working...
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
3
by: Agnes | last post by:
For my company's vfp application. I need to perform same event in .net 1) E.g the user inputs the companycode, system check the companycode, setfocus to that field if the code is invalid, HOWEVER,...
4
by: dgleeson3 | last post by:
Hello all I am creating a VB.Net distributed SQL server 2005 application. Each computer in the system has a database with a table of users and their telephone numbers. Each computer has a...
2
by: jmDesktop | last post by:
I'm using C#, but I don't know that it matters for this question. I know that many experienced folks are on here, so sorry for being off topic. I am finally at a point where I want to and I think...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.