|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> Because then you can put routines on that common base class that are common
> to every class, like ToString() and Equals() and HashCode() and such.
I think that a class for which it doesn't make any sense to have something
like "ToString()" it would be bad design to force it to have it after all.
> On the other hand, maybe it wouldn't be a bad idea to have inheriting from
> an interface actually insert code into your class as necessary. It would
> certainly be a trivial way to make that work in C# at least, if not in other
> languages based on the CIL.
I wonder if it would make garbage collection more complicated because now
you can have references pointing to the middle of an object rather than the
beginning (and it may be the *only* reference pointing to that object, so
the object must not be collected as long as this reference exists, but it
may be more complicated for the GC engine to know this).
> Where have you found multiple inheritance particularly useful in C++?
Wherever implementing multiple interfaces (or a base class and one or
more interfaces) is useful in any OO language, in cases where it would
actually be useful if the "interface" methods could have default
implementations, or if it would be useful if the interface provided
auxiliary methods for the derived class to use.
The problem with "interfaces" is that they are not *helpful* at all.
The don't offer any functionality, any default implementations or any
data. These "interfaces" could often become a lot more helpful if they
actually offered something for the derived class so that it doesn't have
to implement everything from scratch every time.
I'm not saying that every single program I have written (or even a
significant amount of them) uses multiple inheritance, but it has been
useful sometimes.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |