Data Model for Quantity v0.5 - inheritance vs aggregation

Martin Hill mchill at dial.pipex.com
Tue May 11 02:29:22 PDT 2004


Patrick Dowler wrote:

> On Monday 10 May 2004 08:50, Brian Thomas wrote:
> 
> FYI - realization is the relationship between an interface and the class that 
> implements it. One interface still inherits from another. the Q document does 
> specify an inheritance relationship.

Doh - I should have got that too.  But even so:

> As for the point about implementors being free, that is true in principle but 
> bogus in practice. If you have (trying to not be too java-esque here and it 
> doesn't apply just to java anyway):
> 
> interface Frame
> interface CoreQ extends Frame
> interface StdQ extends CoreQ
> 
> then when I write my implementation and I have
> 
> class MyStdQ realizes StdQ // java: implements
> {
>     // must have all methods from Frame, Core, and Std
> }
> 
> Sure, I could write
> 
> class MyFrame realizes Frame 
> {
>    // Frame methods
> }
> 
> followed by
> 
> class MyCoreQ realizes CoreQ inherits from MyFrame
> {
>      // add CoreQ methods here
> }
> 
> OR
> 
> class MyCoreQ realizes CoreQ
> {
>     // add Frame and CoreQ methods here
> }
> 
> BUT the latter would be clearly stupid because I would have implemented frame
> methods twice. So, one clearly has to write monolithic classes or use the 
> specified inheritance tree.

The point about using interface inheritance is that the way the methods 
are implemented are likely to be different; if they look like they'll be 
the same then, as you say, there's something wrong.

> 
> The interfaces in the Q doc specify a type of relationship that the 
> implementations are more or less forced to follow. 
> 
> Interfaces are meant to be declarative ("I have these methods!") first and can 
> - if it is valuable - have an interface heirarchy. Here we have both and it 
> is an extra burden and limitation on implementors.
> 

Yes, and more subtly, interface methods are generally action methods. 
So you can define 'getValue' and the implementation will work out how to 
do that.  Defining getXxxx properties on an interface, where Xxxx is a 
particular class makes the interface too much of a class...



-- 
Martin Hill
www.mchill.net
07901 55 24 66



More information about the dm mailing list