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

Applying multiple design paterns to a single class

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
DeviceManager which is only interested in CD/DVD devices. I want to get
the list of CD/DVD devices and "be informed when a disc inserted into a
device". I am developing this on Linux. So, I used HAL API and read
some system (actually /proc) files to gather required information.
Everything is OK so far. But, at the same time, I want to visualize
this information. I have a dialog which lists the CD/DVD devices and
according to the chosen device it shows the media it contains (says
empty if it has none) To visualize this information I need to notify
the GUI part. Therefore I decided to use "Observer" design pattern.
However, my DeviceManager must be a "Facade" to hide the implementation
details (because, in fact, I used another class to read those system
files). Worse, DeviceManager itself must be an "Observer" to get the
information from the HalHandler to be informed when a new media
inserted or removed.

GUI ("Observer" for DeviceManager)
I
I
Device manager ("Subject" for GUI, "Observer" for HALHandler and must
be "Facade" too)
/ \
/ \
FileOp HALHandler ("Subject" for DeviceManager)

My questions are as follows:

a) Is applying multiple design pattern to a single class
acceptable/normal or does it indicate a wrong design? Because, if I am
not wrong, applying two or more design pattern to a single class may
necessitate multiple inheritance (which might make everything much more
complex than expected)

b) If my design is problematic or wrong what would be the correct
solution/design? Any suggestions/ideas???

Thanks everybody in advance :)

Sep 26 '06 #1
6 2045
Orgun
comp.object is better place (for patterns) forwarding there,

raxit

Sep 26 '06 #2
Sorry to repeat,
this is from comp.lang.c++ forwarding to comp.object,

raxit
Orgun wrote:
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
DeviceManager which is only interested in CD/DVD devices. I want to get
the list of CD/DVD devices and "be informed when a disc inserted into a
device". I am developing this on Linux. So, I used HAL API and read
some system (actually /proc) files to gather required information.
Everything is OK so far. But, at the same time, I want to visualize
this information. I have a dialog which lists the CD/DVD devices and
according to the chosen device it shows the media it contains (says
empty if it has none) To visualize this information I need to notify
the GUI part. Therefore I decided to use "Observer" design pattern.
However, my DeviceManager must be a "Facade" to hide the implementation
details (because, in fact, I used another class to read those system
files). Worse, DeviceManager itself must be an "Observer" to get the
information from the HalHandler to be informed when a new media
inserted or removed.

GUI ("Observer" for DeviceManager)
I
I
Device manager ("Subject" for GUI, "Observer" for HALHandler and must
be "Facade" too)
/ \
/ \
FileOp HALHandler ("Subject" for DeviceManager)

My questions are as follows:

a) Is applying multiple design pattern to a single class
acceptable/normal or does it indicate a wrong design? Because, if I am
not wrong, applying two or more design pattern to a single class may
necessitate multiple inheritance (which might make everything much more
complex than expected)

b) If my design is problematic or wrong what would be the correct
solution/design? Any suggestions/ideas???

Thanks everybody in advance :)
Sep 26 '06 #3
Ed

ra************@yahoo.co.in skrev:
Sorry to repeat,
this is from comp.lang.c++ forwarding to comp.object,

raxit
Orgun wrote:
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
DeviceManager which is only interested in CD/DVD devices. I want to get
the list of CD/DVD devices and "be informed when a disc inserted into a
device". I am developing this on Linux. So, I used HAL API and read
some system (actually /proc) files to gather required information.
Everything is OK so far. But, at the same time, I want to visualize
this information. I have a dialog which lists the CD/DVD devices and
according to the chosen device it shows the media it contains (says
empty if it has none) To visualize this information I need to notify
the GUI part. Therefore I decided to use "Observer" design pattern.
However, my DeviceManager must be a "Facade" to hide the implementation
details (because, in fact, I used another class to read those system
files). Worse, DeviceManager itself must be an "Observer" to get the
information from the HalHandler to be informed when a new media
inserted or removed.

GUI ("Observer" for DeviceManager)
I
I
Device manager ("Subject" for GUI, "Observer" for HALHandler and must
be "Facade" too)
/ \
/ \
FileOp HALHandler ("Subject" for DeviceManager)

My questions are as follows:

a) Is applying multiple design pattern to a single class
acceptable/normal or does it indicate a wrong design? Because, if I am
not wrong, applying two or more design pattern to a single class may
necessitate multiple inheritance (which might make everything much more
complex than expected)

b) If my design is problematic or wrong what would be the correct
solution/design? Any suggestions/ideas???

Thanks everybody in advance :)
The only thing wrong with applying multiple design patterns to one
class is that it violates the somewhat nebulous, "Single Responsibility
Principle," that states that a class should do one thing and one thing
only.

Your alarm at impending complexity, however, seems more relevant. So I
personally would split the behaviour you describe across several
classes.

Firstly, are you using namespaces?

Secondly, as you already have a facade or sorts, why not run with it?
Why not have your facade - DeviceFacade - contain, for example, the
getDeviceNotificationSource() to return the class that will handle
forwarding notifications to observers, and getDeviceManager() to return
that class that can (I suppose) be interrogated for device information.

Similarly, I'd have a separate class within this namespace be reposible
for registering with the HAL and keeping the state of the devices it's
observing.

Importantly, have as few concrete classes visible outside the namespace
as possible - preferably just one: the DeviceFacade - and have only
abstract classes available for the other behaviour visible outside the
namespace (DeviceManager, for instace, should be abstract, and of
course the Observer class that you pass to the HAL will be abstract);
thus, you can decide how to assign behavioural responsibility within
the namespace as you wish, with minimal impacts on other namespaces
that depend on this behaviour.

..ed

--
www.EdmundKirwan.com - Home of The Fractal Class Composition.

Download Fractality, free Java code analyzer:
http://www.EdmundKirwan.com/servlet/...c-page130.html

Sep 26 '06 #4
Sorry. I am new to groups too. Thanks :)

ra************@yahoo.co.in yazdi:
Sorry to repeat,
this is from comp.lang.c++ forwarding to comp.object,

raxit
Orgun wrote:
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
DeviceManager which is only interested in CD/DVD devices. I want to get
the list of CD/DVD devices and "be informed when a disc inserted into a
device". I am developing this on Linux. So, I used HAL API and read
some system (actually /proc) files to gather required information.
Everything is OK so far. But, at the same time, I want to visualize
this information. I have a dialog which lists the CD/DVD devices and
according to the chosen device it shows the media it contains (says
empty if it has none) To visualize this information I need to notify
the GUI part. Therefore I decided to use "Observer" design pattern.
However, my DeviceManager must be a "Facade" to hide the implementation
details (because, in fact, I used another class to read those system
files). Worse, DeviceManager itself must be an "Observer" to get the
information from the HalHandler to be informed when a new media
inserted or removed.

GUI ("Observer" for DeviceManager)
I
I
Device manager ("Subject" for GUI, "Observer" for HALHandler and must
be "Facade" too)
/ \
/ \
FileOp HALHandler ("Subject" for DeviceManager)

My questions are as follows:

a) Is applying multiple design pattern to a single class
acceptable/normal or does it indicate a wrong design? Because, if I am
not wrong, applying two or more design pattern to a single class may
necessitate multiple inheritance (which might make everything much more
complex than expected)

b) If my design is problematic or wrong what would be the correct
solution/design? Any suggestions/ideas???

Thanks everybody in advance :)
Sep 26 '06 #5
First of all, thank you very much for your reply. I am trying to
grab it completely at the moment.

I haven't started using namespaces yet but, I think, it's time
:)

Your suggestions about getDeviceNotificationSource() and
getDeviceManager(), I think, the "pull model" described in GoF. Am i
wrong?

I already have a separate HALHandler class. Maybe I need
different Facade and Manager classes for convenience. Manager can use
HALHandler and can be interrogated, Facade supply an easy-to-use
interface for the device management job. I am not sure at the moment
but I will, soon.

Thanks again.
Orgun

Ed yazdi:
ra************@yahoo.co.in skrev:
Sorry to repeat,
this is from comp.lang.c++ forwarding to comp.object,

raxit
Orgun wrote:
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
DeviceManager which is only interested in CD/DVD devices. I want to get
the list of CD/DVD devices and "be informed when a disc inserted into a
device". I am developing this on Linux. So, I used HAL API and read
some system (actually /proc) files to gather required information.
Everything is OK so far. But, at the same time, I want to visualize
this information. I have a dialog which lists the CD/DVD devices and
according to the chosen device it shows the media it contains (says
empty if it has none) To visualize this information I need to notify
the GUI part. Therefore I decided to use "Observer" design pattern.
However, my DeviceManager must be a "Facade" to hide the implementation
details (because, in fact, I used another class to read those system
files). Worse, DeviceManager itself must be an "Observer" to get the
information from the HalHandler to be informed when a new media
inserted or removed.
>
GUI ("Observer" for DeviceManager)
I
I
Device manager ("Subject" for GUI, "Observer" for HALHandler and must
be "Facade" too)
/ \
/ \
FileOp HALHandler ("Subject" for DeviceManager)
>
My questions are as follows:
>
a) Is applying multiple design pattern to a single class
acceptable/normal or does it indicate a wrong design? Because, if I am
not wrong, applying two or more design pattern to a single class may
necessitate multiple inheritance (which might make everything much more
complex than expected)
>
b) If my design is problematic or wrong what would be the correct
solution/design? Any suggestions/ideas???
>
Thanks everybody in advance :)

The only thing wrong with applying multiple design patterns to one
class is that it violates the somewhat nebulous, "Single Responsibility
Principle," that states that a class should do one thing and one thing
only.

Your alarm at impending complexity, however, seems more relevant. So I
personally would split the behaviour you describe across several
classes.

Firstly, are you using namespaces?

Secondly, as you already have a facade or sorts, why not run with it?
Why not have your facade - DeviceFacade - contain, for example, the
getDeviceNotificationSource() to return the class that will handle
forwarding notifications to observers, and getDeviceManager() to return
that class that can (I suppose) be interrogated for device information.

Similarly, I'd have a separate class within this namespace be reposible
for registering with the HAL and keeping the state of the devices it's
observing.

Importantly, have as few concrete classes visible outside the namespace
as possible - preferably just one: the DeviceFacade - and have only
abstract classes available for the other behaviour visible outside the
namespace (DeviceManager, for instace, should be abstract, and of
course the Observer class that you pass to the HAL will be abstract);
thus, you can decide how to assign behavioural responsibility within
the namespace as you wish, with minimal impacts on other namespaces
that depend on this behaviour.

.ed

--
www.EdmundKirwan.com - Home of The Fractal Class Composition.

Download Fractality, free Java code analyzer:
http://www.EdmundKirwan.com/servlet/...c-page130.html
Sep 26 '06 #6
Responding to Raxitsheth2000...
> I am new to Design Patterns. I want to write a simple
DeviceManager which is only interested in CD/DVD devices. I want to get
the list of CD/DVD devices and "be informed when a disc inserted into a
device". I am developing this on Linux. So, I used HAL API and read
some system (actually /proc) files to gather required information.
Everything is OK so far. But, at the same time, I want to visualize
this information. I have a dialog which lists the CD/DVD devices and
according to the chosen device it shows the media it contains (says
empty if it has none) To visualize this information I need to notify
the GUI part. Therefore I decided to use "Observer" design pattern.
However, my DeviceManager must be a "Facade" to hide the implementation
details (because, in fact, I used another class to read those system
files). Worse, DeviceManager itself must be an "Observer" to get the
information from the HalHandler to be informed when a new media
inserted or removed.

GUI ("Observer" for DeviceManager)
I
I
Device manager ("Subject" for GUI, "Observer" for HALHandler and must
be "Facade" too)
/ \
/ \
FileOp HALHandler ("Subject" for DeviceManager)

My questions are as follows:

a) Is applying multiple design pattern to a single class
acceptable/normal or does it indicate a wrong design? Because, if I am
not wrong, applying two or more design pattern to a single class may
necessitate multiple inheritance (which might make everything much more
complex than expected)

b) If my design is problematic or wrong what would be the correct
solution/design? Any suggestions/ideas???
While there is nothing inherently wrong with chaining design patterns
together, it is suspicious in a single object. Thus there is nothing
wrong with the same object playing different subject/observer roles in
the implementation to two separate Observer patterns. But throwing in a
Facade as well seems a bit much. Here, my suspicions are further
aroused by the name "DeviceManager". All too often XxxManager or
XxxController class names are symptoms of god objects with too many
responsibilities or of higher level nodes in a functional decomposition.

So I am suspicious that there are more objects that abstract the notion
of 'device manager'. But before speculating on what they might be, I
would need to know more about what is being managed. For example, are
your reading and displaying disc content? Or is your application
limited to just providing a directory structure view?

I am also concerned about cohesion at the subsystem level. A GUI UI
would usually be in its own subsystem. That's because the
Window/Control paradigm is so unique. I would expect that to be the
case unless the UI is trivial. If the UI is in its own subsystem then
the subsystem interface provides a Facade to decouple its semantics from
the rest of the application.

I would apply a similar argument to FileOp if you need content from the
discs. That functionality is complex and unique enough to justify its
own subsystem where the level of abstraction is device driver reads and
writes. That would provide you will a Facade for that aspect.

I know nothing about HAL, but I assume that interface is pretty simple.
In that case you can use a HALHandler object that acts as a surrogate
for talking to the OS. That object would provide the same sort of
decoupling from the OS as a Facade would.
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hs*@pathfindermda.com
Pathfinder Solutions
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
"Model-Based Translation: The Next Step in Agile Development". Email
in**@pathfindermda.com for your copy.
Pathfinder is hiring:
http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH

Sep 26 '06 #7

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

Similar topics

4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
7
by: sasquatch | last post by:
Hi, I've a a site with nested master pages and content pages. I tried using a theme with a stylesheet in the app_themes directory referencing it in the web.config file from a pages tag theme...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
10
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under...
2
by: Immortal Nephi | last post by:
You may have heard diamond shape. You create one base class. One base class has member functions and member variables. You create two derived classes. All member functions and member variables...
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: 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: 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
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
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...

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.