Newbie Modelling Interface Question
From: AdamJoe (adamjoe1_at_yahoo.co.uk)
Date: 10/25/03
- Next message: H. S. Lahman: "Re: Visitor, dynamic_cast or ..."
- Previous message: JXStern: "Re: OO's best feature survey results"
- Next in thread: Daniel T.: "Re: Newbie Modelling Interface Question"
- Reply: Daniel T.: "Re: Newbie Modelling Interface Question"
- Reply: H. S. Lahman: "Re: Newbie Modelling Interface Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 25 Oct 2003 20:08:48 +0100
Hi all,
I'm fairly new to this game so please bear that in mind when posting a
reply. I'm trying to figure out the best way to model the following problem.
I have an architecture made up of a number of subsystems, one of which is a
Hardware Interface subsystem. A client's access to this subsystem is
restricted to the interfaces it realises. The client will hold a pointer(s)
to the abstract type of the interface(s) and use it to invoke the
appropriate methods on the derived class(es).Inside this subsystem I have
two classes, amongst others, Fram and Rom, which implement the following
methods.
Fram
Read
Write
CrcCheck
Rom
CrcCheck
It is anticipated in the future that there will be other memory types. I
would like to define an interface or interfaces for this subsystem that
these classes can derive from and clients can depend on.
One option I've considered is to have two interfaces. The first is IMemory,
which Rom derives from and provides one pure virtual function, CrcCheck. The
second is IRWMemory which Fram derives from and provides pv functions Read,
Write, and CrcCheck. The client then has a pointer to each interface.
Another option is to have two interfaces again but one derives from the
other. IRWMemory would derive from IMemory and inherit its CrcCheck
operation. Rom would derive from IMemory and Fram from IRWMemory. Again the
client would have a pointer to each interface.
A third option is to have one interface that supports all the methods and
both Rom and Fram would derive from it. In Rom's case, it would have to
generate an exception or whatever was appropriate if the client tried to
invoke a Read or Write operation on it. This seems to me to be the least
elegant of the three and if I implemented it this way there wouldn't be much
point in the interface as not all derived classes would be able to implement
the operations it supports.
Make sense?
I'm not sure how good or bad these solutions are. I can't find anything that
helps in any books or on any of these newsgroups. I'm looking for feedback
on what is wrong or right with this approach and any other potential options
that I've not considered would be appreciated.
Thanks in advance,
Adam.
- Next message: H. S. Lahman: "Re: Visitor, dynamic_cast or ..."
- Previous message: JXStern: "Re: OO's best feature survey results"
- Next in thread: Daniel T.: "Re: Newbie Modelling Interface Question"
- Reply: Daniel T.: "Re: Newbie Modelling Interface Question"
- Reply: H. S. Lahman: "Re: Newbie Modelling Interface Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|