Re: Design issue with constructor arguments
- From: "Mark Nicholls" <Nicholls.Mark@xxxxxxxxx>
- Date: 7 Dec 2006 05:48:41 -0800
Caroline M wrote:
Hi all,
I'm writing a C++ program and I've come across a design issue that I
seem to keep getting but I dont know if it has a name or something.
I am writing a library which is to be used by some client code. In this
library I have a single front end class which acts as a kind of facade
into the library. Clients can instantiate one of these to gain the use
of the library. Internally, I have many classes and one of these is a
special processing class which invokes callback function supplied by
the client.
Thus this processing class has functions to allow the client to
register and unregister callback functions but they dont get to use
this class directly - those functions are mirrored on my front end
class. So the idea is that the front end class instantiates the
processor and fowards requests to register callbacks. All good so far.
The problem that I am experiencing is that internally, the classes that
need to use this processor are buried way down in the internals of the
library. There are something like five classes in between the front end
and the one that actually needs a reference to this processor.
Currently, I instantiate the processor and then pass a reference to it
via constructor calls. This pattern is repeated through these five
classes - each passing the reference down to the next class. But these
classes in the middle really shouldn't have any knowledge of the
processor.
It would be a lot easier to describe this with a simple diagram so I
hope I have made sense! Basically, I want class A, to create an
instance of class B and give it to class X, without having to give it
to class C who gives it to D who gives it to E etc etc and finally it
gets to X.
Any ideas?
So the problem is that class A cannot see class X, so it has to
recursively delegate to a class that can see it?
OK, there may be nothing wrong, it may be a symptom of your (correct)
partitioning of the software to minimize coupling, it may be that you
overdone it, or it may be that you've done it 'wrong'.
It feels slightly wrong only because you say that C & D have no real
interest in X except to pass this parameter in, so why can't A see X
directly?
It feels as if you have partioned the system into strick layers, where
possibly the system would be simpler if it were more 'lumpy'.
(it may be that you've done everything sensibly, and it's just a
reflection of you minmising coupling).
.
- Follow-Ups:
- Re: Design issue with constructor arguments
- From: Caroline M
- Re: Design issue with constructor arguments
- References:
- Design issue with constructor arguments
- From: Caroline M
- Design issue with constructor arguments
- Prev by Date: Design issue with constructor arguments
- Next by Date: Re: Design issue with constructor arguments
- Previous by thread: Design issue with constructor arguments
- Next by thread: Re: Design issue with constructor arguments
- Index(es):
Relevant Pages
|