POV-Ray : Newsgroups : povray.off-topic : Generics annoyance : Re: Generics annoyance Server Time
4 Sep 2024 15:21:31 EDT (-0400)
  Re: Generics annoyance  
From: Warp
Date: 14 Apr 2010 13:53:24
Message: <4bc60113@news.povray.org>
Darren New <dne### [at] sanrrcom> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.