How to access one specific lowlevel object through a general highlevel interface?
- From: "Rob Clark" <se@xxxxxx>
- Date: Tue, 20 Dec 2005 11:23:52 +0100
Hello all,
I have a problem for which my solution feels like a hack. :-(
I'd like to change that :-)
The real problem can be destilled to something like this:
One client wants to send data using one specific top layer
protocol. At this top layer, there are a number of different
protocols, where each one inherits the main Protocol class.
And every protocol subclass in turn contains several different
communication channels that inherits the Channel class.
So, a client knows about several different high level protocols
and each protocol has many channels.
Now, when data is to be sent, we must send that data over the
"most appropriate" communication channel. This channel can be
found by traversing the hierarchy of protocols and channels.
However, after we have found the "best" channel, we cannot send
data through this channel directly! Instead we must send data
through the specific protocol which the selected channel belongs to.
Therefore, one can let each channel be aware of its parent protocol,
and this allows for a solution to expressed in code like:
Channel* channel = GetBestChannel();
Protocol* protocol = channel->GetProtocol();
protocol->SendData(channel,"Hello world!");
where
ProtocolX::SendData(const Channel* channel, const char* data)
{
// First...
DoSomeProtocolXSpecificStuff();
// Then send the data through the selected channel
channel->SendData(data);
}
The things that I do not like about this solution is that I do not
want the Channel class to be unveiled. The client shouldn't
care about the channels, it shouldn't be aware of their existance.
In addition to this, I do not like that each channel must be aware
of its parent protocol.
So, is there another solution for this recurring(?) problem, a pattern
maybe, or do I have to accept my current solution?
/Rob
.
- Follow-Ups:
- Prev by Date: Re: Small Cohesive Objects - Configuration
- Next by Date: Re: Multiple controllers hierarchy?
- Previous by thread: #ifdef vs. OO Design Patterns
- Next by thread: Re: How to access one specific lowlevel object through a general highlevel interface?
- Index(es):
Relevant Pages
|