Re: Newbie Modelling Interface Question

From: Daniel T. (postmaster_at_earthlink.net)
Date: 10/26/03


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.



Relevant Pages

  • Newbie Modelling Interface Question
    ... Hardware Interface subsystem. ... two classes, amongst others, Fram and Rom, which implement the following ... second is IRWMemory which Fram derives from and provides pv functions Read, ...
    (comp.object)
  • Re: WPC software changes possible?
    ... interfaces with the extant driver boards. ... grey area there because the DMD animations are stored on the gamerom ... AFAIK - not the sound rom) ... to re-works of the WPC system or interface to, ...
    (rec.games.pinball)
  • Re: Remoting Objects: style question
    ... Most likely, if you use abstract objects, the first cast will be done in the ... class to which it is cast, regardless of whether it derives from that class. ... acobj will be non-null even though the remoted object is ... > the object actually implements the interface). ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: 1800 Router Internet not working after power failure
    ... ROM: System Bootstrap, Version 1 ... Provenir uptime is 2 hours, ... Serial interface ... input packets with dribble condition detected ...
    (comp.dcom.sys.cisco)
  • RE: Implementing custom interfaces
    ... that derives from SoapHttpClientProtocol. ... implemented in this file will not have derived from your interface even if ... I have created a web service which implements a custom interface. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)