From: Kuba Ober <ober.14@osu.edu>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] C++/C# inheritance is bad?
Date: Sat, 17 Jan 2009 09:35:22 -0500 [thread overview]
Message-ID: <D035AED0-188D-4EF5-BB9A-BE39537B1A70@osu.edu> (raw)
In-Reply-To: <200901171327.19141.jon@ffconsultancy.com>
On Jan 17, 2009, at 8:27 AM, Jon Harrop wrote:
> On Friday 16 January 2009 15:18:50 Kuba Ober wrote:
>> So, when correctly applied, what's so disturbing about inheritance?
>
> Inheritance is disturbing because, in general, it cannot be applied
> correctly.
> That is why there are so many workarounds, many of which do not even
> exist in
> C++ like final methods, sealed classes, multimethods, extractors and
> so on.
> OO is not good in all circumstances and other tools can be
> preferable. IME,
> OO is only very rarely the best solution and it is only chosen so
> often
> because it is typically the only solution available (e.g. in C++ or
> Java).
>
>> You inherit only where it makes sense, and if it makes sense then
>> you don't
>> care about which particular method is called: it's supposed to be
>> safe.
>
> Safety is quite different from easy of use, of course.
I know I'm perhaps overusing Qt as an example, but it's just handy.
In Qt, the basic "instrumented" class is QObject. It implements
retrospection,
signal/slot mechanism, etc. QWidget (a GUI building block) derives
from it.
(and from a QPaintDevice, since you can paint on it).
Then, you have various widgets that derive from QWidget. Some of those
are abstract widgets (interfaces), like QAbstractButton, where a
concrete
class faces the end user, like QPushButton.
It is quite a straightforward model -- as long as you think of it in
terms of "ISA"
relationship between classes.
I wonder how such a hierarchy would be implemented in a natural way
in OCaml? By "natural" I mean being good practice and not feeling like
a hack.
One should remember that users must extend the framework, so it should
be easy to extend say QWidget to create your own "class".
Cheers, Kuba
next prev parent reply other threads:[~2009-01-17 14:35 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-16 15:18 Kuba Ober
2009-01-16 15:58 ` [Caml-list] " Richard Jones
2009-01-16 16:28 ` On the benefits of OO, Was: " Jan Kybic
2009-01-17 12:40 ` Oliver Bandel
2009-01-16 18:27 ` Raoul Duke
2009-01-16 21:42 ` Kuba Ober
2009-01-17 3:14 ` Sashan Govender
2009-01-17 14:07 ` Kuba Ober
2009-01-18 6:24 ` Stefano Zacchiroli
2009-01-17 13:27 ` Jon Harrop
2009-01-17 14:35 ` Kuba Ober [this message]
2009-01-17 16:59 ` Jon Harrop
2009-01-17 21:22 ` Kuba Ober
2009-01-17 22:17 ` Jon Harrop
2009-01-17 23:29 ` David Teller
2009-01-17 23:49 ` Jon Harrop
2009-01-19 16:22 ` Visitor in OCaml [was Re: [Caml-list] C++/C# inheritance is bad?] Yoann Padioleau
2009-01-19 16:41 ` blue storm
2009-01-19 17:49 ` Richard Jones
2009-01-19 17:52 ` Visitor in OCaml Christophe TROESTLER
2009-01-21 20:09 ` Yoann Padioleau
2009-01-22 4:03 ` [Caml-list] " Yaron Minsky
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=D035AED0-188D-4EF5-BB9A-BE39537B1A70@osu.edu \
--to=ober.14@osu.edu \
--cc=caml-list@yquem.inria.fr \
/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