POV-Ray : Newsgroups : povray.general : CSDL: C-like Simulation Description Language : Re: CSDL alpha 1 release Server Time
7 Aug 2024 07:19:19 EDT (-0400)
  Re: CSDL alpha 1 release  
From: Warp
Date: 24 Jan 2002 07:12:05
Message: <3c4ffa14@news.povray.org>
The main problem with downcasting is that it destroys abstraction quite
effectively.
  The whole idea of having a base class is abstraction: A base class describes
a general set of objects (in a more or less abstract way), and every inherited
class is by definition a base class as well.
  This means that if a function/method takes a base class handle (handle =
reference or pointer), this function/method is at the same abstraction level
as the base class itself. That is, this function/method works for *every*
object which has been inherited from the base class (the function/method
doesn't need to know any inherited object type and still work with them).
You can create new classes inherited from the base class (or from its children
classes), and this function/method will work fine with them.

  Now, if this function/method performs downcasting and relies on it in order
to function properly, this abstraction is effectively broken. Now you are
saying that this function/method works just for this, this and that inherited
object, and nothing else. If you later want to add a new inherited class,
you'll have to modify this function/method in order to support the new class
(and this might not always be even possible if you don't have access to its
source code). This is not very modular.
  If there's a functionality which is specific to a certain class, that
functionality should be implemented in that class. If several classes with
a common base class have similar functionalities (but which are implemented
in a different way), then there should be an abstract way of calling this
functionality in the base class.
  It's always better to do "downcasting" with a virtual function call instead
of doing it "by hand".

  (Yes, I know, there might be hundreds of exceptions to this generic rule,
but I have noticed in my work that they really are *exceptions*, and that they
are not common at all.)

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

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