[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
interfaces (was: Re: Curl, multiple inheritance, and interfaces (was Re: cheerful static typing))
It seems to me that interfaces are the key component of object-oriented
languages that makes them really useful. Think about it: you could get rid
of encapsulation and your life would be harder, but you could live with it
(e.g. python programmers rarely use private variables). You could get rid
of inheritance, and you would have to write a lot more code, but you could
probably live with that too (e.g. java's prohibition on multiple
implementation inheritance hasn't hurt that much). But if you don't have
interfaces that different classes can implement independently of any
knowledge of each other, then you don't have OO in any useful sense. Even
though interfaces are usually viewed (e.g. in C++) as being a limiting case
of a class where all methods are virtual, it doesn't have to be that way.
The language Sather, for instance, has a very interesting object system
where interfaces are completely orthogonal to inheritance; interfaces deal
with subtyping (and hence polymorphism), whereas implementation inheritance
is done using "code inclusion". The former is viewed as essential to OO
while the latter is just a convenience. There are some experimental ML
dialects that do the same thing (Moby?). I would like to see more
statically-typed languages moving in this direction.
> From: "Anton van Straaten" <firstname.lastname@example.org>
> Date: Thu, 10 Jan 2002 18:11:30 -0500
> Dan Weinreb wrote:
> > in Java, it's
> > impossible to ignore interfaces
> > Well, I wouldn't describe Java with words that strong. You could
> > imagine an alternative design in which every class must implement some
> > interface; that would make it impossible to ignore interfaces. With
> > Java, you can have classes that do inheritance, and that have abstract
> > methods, without using Java interfaces.
> You're right; interfaces are "impossible to ignore" in Java not because of
> the language itself, but because of its libraries, which make heavy use of
> interfaces. Still, I think the mere act of putting the keyword 'interface'
> into the Java language did a lot to disseminate good program design
> practices and thinking. It identifies interfaces as entities distinct from
> classes, as opposed to relegating them to a kind of subordinate category of
> classes - "classes without an implementation".
> This class-bias affects the thinking of many of the users of such languages,
> especially those who develop primarily or exclusively in a single language.
> It commonly leads to code which over-emphasizes specific implementations and
> under-emphasizes properly factored abstractions. Abstractions then tend to
> be designed around the opportunities for implementation inheritance, which
> is definitely the tail wagging the dog.
> Of course, a language can't fix or prevent bad program designs, but it can
> help get programmers thinking in good (or bad!) directions.