Browse thread
C++/C# inheritance is bad?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2009-01-17 (14:35) |
From: | Kuba Ober <ober.14@o...> |
Subject: | Re: [Caml-list] C++/C# inheritance is bad? |
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