[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: s-exprs + prototypes
> Date: Sun, 22 Jun 2003 03:08:02 -0700
> From: Colin Putney <cputney@wiresong.ca>
>
> Equating inheritance with objects is a red herring, IMO. It's just a
> detail of how popular object systems have typically been implemented.
> In dynamically typed OO languages, it's a way to organize code reuse.
> In statically typed languages it doubles as a type hierarchy.
>
> Classes and prototypes are just different styles of OO, in much the
> same way that CLOS is a "style" of LISP. With appropriate libraries,
> you can do class-based OO in prototype languages and vice-versa.
>
> The essence of objects is encapsulation.
Disagree. The essence of objects is polymorphism. Encapsulation makes a
system "object-based" but not "object-oriented" (as the terms are usually
used). Polymorphism, of course, means you can send the same message to
different objects (or set of objects, for multiple-dispatching object
systems) and it does something different for each object (or set of
objects). The distinction is much more glaring in statically-typed
languages than in dynamically-typed languages, and especially in C++ where
you have to explicitly declare a method "virtual" in order to get
polymorphism (otherwise you have encapsulation but no polymorphism).
However, you are right that inheritance is not necessary to get
polymorphism either, at least in dynamically-typed languages. But it's
pretty unusual to see an object system without inheritance. Of course,
with first-class functions you could get by with explicit delegation to
methods of another object.
Considering this, I take back what I said before. What I should have said
was:
The big difference is that functions have no notion of dispatching on the
types of the arguments, whereas objects do. There are different ways of
handling this, none of which are manifestly the "best" way. So the
supposed generality of objects is IMO an illusion.
Mike