Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: John Prevost <j.prevost@gmail.com>
Cc: Caml Mailing List <caml-list@inria.fr>
Subject: Re: Re: [Caml-list] Restricting Method Overriding/Redefinition in Subclass
Date: 15 Aug 2004 03:17:13 +1000	[thread overview]
Message-ID: <1092503833.29139.668.camel@pelican.wigram> (raw)
In-Reply-To: <d849ad2a04081409283cf52583@mail.gmail.com>

On Sun, 2004-08-15 at 02:28, John Prevost wrote:

[structural subtyping]

> At this point, you may be wondering "Why is O'Caml like this?

My stupid answer is "because its correct". 

The kind of subtyping by subclassing used in Java
and C++ is really awkward to use.

Basically the problem is, to extend the capabilities
of your object heirarchy, you inevitably have to 
add a new method to a base class, or equivalently
derive from  an extra base class containing it -- 
which breaks the principle of encapsulation that is 
supposedly the foundation of object orientation: 
such breakage is said to be invasive, and it contravenes the
Open/Closed principle (see Meyer).

This isn't the case for structural subtyping,
where A is a subtype of B simply if it is one --
you don't have to derive A from B -- which might
not even exist at the time you write A.

This means you can write algorithms that work
on sets of classes sharing some properties
(such as a collection of methods) AFTER you define
the classes without invading the class definitions
-- in Java or C++ you'd have to add inheritance
specifications to make this work.


-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2004-08-14 17:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-14  0:03 chris.danx
2004-08-14  7:38 ` skaller
2004-08-14 16:28   ` John Prevost
2004-08-14 17:17     ` skaller [this message]
2004-08-18 12:04     ` chris.danx
2004-08-18 19:47       ` John Prevost
2004-08-18 22:21       ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1092503833.29139.668.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=j.prevost@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox