POV-Ray : Newsgroups : povray.advanced-users : Object Oriented POV code : Re: Object Oriented POV code Server Time
29 Jul 2024 08:14:31 EDT (-0400)
  Re: Object Oriented POV code  
From: Warp
Date: 23 Feb 2004 18:18:50
Message: <403a8a59@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> >   So basically what you want is to support multiple inheritance, but
> > without the possibility of grouping common functionality to the
> > "base classes" (ie. "interfaces" in this case) but forcing the inherited
> > classes to implement everything again and again?

> Right. It avoids a fairly wide range of problems, both semantic and 
> efficiency.

  So because the makers of the compiler are lazy they force the
user of the language to make bad code?

  C++ does multiple inheritance quite efficiently, and even if it didn't,
why should it matter? You just need to know how heavy multiple inheritance
is and then decide whether to use it or not in your application. However,
if you have a place where it would be extremely useful then it's good that
you have the possibility.
  One could argue that virtual functions are inefficient because they
produce internally an indirect function call (subroutine call to an
address got from behind a pointer got from behind a pointer), which
potentially make them slightly slower than regular function calls.
Does this mean virtual functions should be left out? Of course not.
You just need to be aware of what they do.

> Also, diamond-shaped inheritance is problematic, semantically speaking.

> For one: If D inherits from B and C, and both B and C inherit from A, 
> and A declares instance variables, how many copies of that instance 
> variable show up in D?

  Diamond-inheritance is truely rare, so if you want to forbid that
special situation IMHO you can. However, don't forbid *all* multiple
inheritances because of one specific case.
  In C++ if you want the base class to appear only once in the
bottommost inherited class in diamond-inheritance, you can make
the member variables of the base class virtual.

> A is a vehicle
> B is a plane
> C is a boat
> D is a hydroplane

  That was a classical example of bad OO design, so I don't think you
should be using it to demonstrate your point. ;)

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

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