POV-Ray : Newsgroups : povray.general : object oriented features : Re: object oriented features Server Time
28 Jul 2024 14:33:16 EDT (-0400)
  Re: object oriented features  
From: Warp
Date: 18 Aug 2000 10:26:34
Message: <399d479a@news.povray.org>
In povray.general Mikael Carneholm <sa9### [at] idautbhbse> wrote:
: // IDENTIFIER = like ANCESTOR, or actually: SUBOBJECT = like SUPEROBJECT (is
: "from" better than "like" maybe?)

  Perhaps the best name would be "is_a".

  1. Inheritance (at least public inheritance) is always an "is a" relation.
The inherited class "is a" base class.
  For example if we have a base class Vehicle and we inherit a class Car from
it and then we inherit a class Opel from it, the "is a" relation is clear:
  Opel is a Car, and Car is a Vehicle.

  2. The "is a" relation means that an instance of the derived class can be
used anywhere an instance of the base class is used. This means that the
derived class must contain all the functionality of the base class.

  The second note is important. Sometimes one can do bad inheritance if only
the first thing is taken into account. For example one could think that
a Circle "is a" Ellipse so one could (wrongly) make an Ellipse base class and
inherit a Circle class from it. However, a Circle does not have the same
functionality as the Ellipse (eg. you can't set two radiuses).

  It is considered bad OO design to inherit from another class only to make
a "copy" of that class with some modification. For example if I have the
class IceCream, which describes a chocolate ice cream and then I inherit
a StrawberryIceCream from it, to make a similar ice cream, but with
strawberry flavor, that's bad OO design.
  The correct way is to make a (possibly abstract) base class IceCream and
then inherit different flavored classes from it, eg. ChocolateIceCream and
StrawberryIceCream. Now there's a true "is a" relation between inherited
and base classes.

  Why do I write all this? Because I didn't like your example:

: #declare worm_part2=like worm_part1{
:   pigment{color rgb 0}  // leaves everything like worm_part1, except the pigment.
: }

  You are making a strawberry ice cream from a chocolate ice cream here :)

: ....and this last block would be polymorphism, don't you think, Warp? Well of
: course, we don't call common-named methods with different implementations here (as
: the well taught OO student points out), but the <object>.location expression is
: referencing different object types with common attribute names.

  That's not polymorphism, it's dynamic binding.
  Yes, a true OO feature.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

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