B
Bart Simpson
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?.
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?.