Re: Debate on use of sub interfaces and poly-morphism

From: Chris Uppal (chris.uppal_at_metagnostic.REMOVE-THIS.org)
Date: 09/27/04


Date: Mon, 27 Sep 2004 10:19:10 +0100

Christian Bongiorno wrote:

> So, basically the debate boils down to this:
> Do I use generic types in a super interface to reduce copy & paste
> (something I despise) or do I apply C&P to a few interface methods and
> thus enforce specific subtypes and relieve the caller of casting?

Doesn't it depend on /why/ the duplication exists ?

If the interfaces have these elements in common because they mean the same
thing, and because it is semantically /necessary/ for them to share those
members (so that, for instance, if one changes then they all change), then you
should express that fact by factoring out the common interface.

If, OTOH, it is only a sort of coincidence that they are so similar (as sounds
likely to me), then using common interface would be actively misleading.
(Especially in the absence of C++-style private inheritance, which can be used
for such cases where it is expedient to inherit functionality, but the
inheritance doesn't really /mean/ anything.)

    -- chris



Relevant Pages

  • Re: Tired of 100s of stupid Getter/Setter methods
    ... but interface does not hide the other methods of implementing ... telling you that you need to refactor a new common superclass. ... Again, composition instead of inheritance. ... A StringVector cannot take Integer parameters. ...
    (comp.lang.java.programmer)
  • Re: A taxonomy of types
    ... (I do not see why inheritance is required here.) ... without an »object-oriented programming language«, for example, ... in the programming language used. ... indirectly) implements an interface IA whose declaration ...
    (comp.lang.misc)
  • Re: Beginner, Which language
    ... > That's much more true for implementation inheritance than interface ... > compared to the run time support Java requires. ... > - All base classes of the interface must also be declared with interface ...
    (comp.programming)
  • Re: Pulling my hair out, I need some help
    ... base class was just that i noticed that a base class saved me more typing ... as using the interface, to the other programmers in my company i made both ... is that the plug-in must meet. ... Inheritance, it is less clear which methods and properties of the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Question on abstract classes versus interfaces
    ... do you conside single inheritance of interface inheritance at all? ... And there is inheritance between Java interfaces, ... of my abstract data types, ...
    (comp.lang.java.programmer)