POV-Ray : Newsgroups : povray.general : object oriented features : Re: object oriented features Server Time
28 Jul 2024 12:29:20 EDT (-0400)
  Re: object oriented features  
From: Mikael Carneholm
Date: 18 Aug 2000 08:39:14
Message: <399D2E6F.2CA7F039@ida.utb.hb.se>
Warp wrote:

>   Sorry for whining, but you (and apparently everyone else) keep calling
> this object oriented although it isn't.
>   Yes, this is an essential part of an object oriented language, but it's
> not object oriented in itself.
>   What you are talking about are modules. A programming language can use
> modules without being an OO language (for example modula2 is one of those).
> These languages have modules which have member functions and member variables,
> public and private parts and so on. This, however, is not yet OO.
>   For a programming language to be OO it has to have modules as in any
> modular language AND it has to have support for inheritance, dynamic binding
> and polymorphism. A program is object oriented when it uses these features
> (mainly inheritance and dynamic binding). Else it just uses modules.

Who said OO-POV shouldn't allow inheritance and polymorphism? If the examples in
my long post does not look like inheritance and polymorphism to you, I apologize.
But, for clarity, here they are, again:

// A "base class" (object) for our worm:
#declare worm_part1=sphere{
 0, 0.5
 pigment{color rgb 1}
 ref{next}  // tells POV that this object has a reference, called "next"
}

// Inheritance...don't you think, Warp? :)
// IDENTIFIER = like ANCESTOR, or actually: SUBOBJECT = like SUPEROBJECT (is
"from" better than "like" maybe?)
#declare worm_part2=like worm_part1{
  pigment{color rgb 0}  // leaves everything like worm_part1, except the pigment.
}

// references can also be declared to "point" to a certain objects from the start:

#declare worm_head=sphere{
 0, 0.5
 texture{some_texture}
 ref{next, worm_part1} // REFNAME [,OBJECT]
}

// Changing the reference of worm_part1:
#declare worm_part1.next=worm_part2;

// Let's create an explicit reference:
#declare temp_ref=ref{worm_head};

// All references are nil:ed from start (if no reference object is
given), so we now can do this:
#while(temp_ref<>nil)
 #declare temp_ref.location = temp_ref.location + <1,0,0>;
 #declare temp_ref=temp_ref.next;
#end

....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.

And another thing: OO in POV should be easy enough for everyone to use - one
should not have to study OO theory in order to use it. That's the reason for the
somewhat "crippled" implementation of OO suggested here.

----------------------------------------------------
Mikael Carneholm, B.Sc.
Dep. of Computer Science and Business Administration


Personal homepage:
http://www.studenter.hb.se/~arch
E-mail:
sa9### [at] idautbhbse


Post a reply to this message

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