Re: Newbie Modelling Interface Question
From: Daniel T. (postmaster_at_earthlink.net)
Date: 10/26/03
- Next message: Daniel T.: "Re: Basic books on OOA&D"
- Previous message: Daniel T.: "Re: Visitor, dynamic_cast or ..."
- In reply to: AdamJoe: "Newbie Modelling Interface Question"
- Next in thread: H. S. Lahman: "Re: Newbie Modelling Interface Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 26 Oct 2003 20:09:53 GMT
"AdamJoe" <adamjoe1@yahoo.co.uk> wrote:
> 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
Why doesn't Rom have a "Read" method?
> 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.
Assuming pure interfaces, the above two solutions are nearly identical.
The only difference is that with the second solution, client classes
that only want to do crcChecks will be able to easily operate on both
kinds of memory. I would say this makes the second solution superior.
I would be weary of calling the master class "IMemory" though, is it
possible of one day having a type of memory that can't do crc checks?
> 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.
I would say this is a poor solution. You would end up having to litter
your code with either down casts, or exception checks.
- Next message: Daniel T.: "Re: Basic books on OOA&D"
- Previous message: Daniel T.: "Re: Visitor, dynamic_cast or ..."
- In reply to: AdamJoe: "Newbie Modelling Interface Question"
- Next in thread: H. S. Lahman: "Re: Newbie Modelling Interface Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|