POV-Ray : Newsgroups : povray.off-topic : Design patterns : Re: Design patterns Server Time
7 Sep 2024 07:21:43 EDT (-0400)
  Re: Design patterns  
From: Warp
Date: 5 Jul 2008 04:40:34
Message: <486f3381@news.povray.org>
There really *are* design patterns which might sound obvious to you
and me, but are not all that obvious to many programmers who are starting
to dig into OOP.

  One example I like (and which name I rather ironically cannot remember
now) is the design pattern which you can use to create primitives and
unions of primitives, so that the union itself is a primitive (thus
allowing a union to contain other unions, containing other unions,
thus forming a whole hierarchy of primitives).

  For example, let's assume that you have three primitives: Line, rectangle
and circle, and you also want to be able to make compound objects containing
any amount of those (so that you can, for example, transform all of them
as if they were one single primitive). Of course it would be nice if such
a compound object could contain other compound objects as well. Thus this
compound object should be a primitive itself.

  Hence the inheritance hierarchy would be something like this:

Primitive
  '--> Line
  '--> Rectangle
  '--> Circle
  '--> Union
         '--Contains: List of <Primitive>

  In other words, if that was drawn as an UML diagram, there would be
a "contains" arrow from 'Union' back to 'Primitive', making the hierarchy
recursive.

  This is a simple idea and might be obvious to some, but it certainly
might not obvious to the new OO programmer.

  The book Design Patterns is full of tidbits like this, making it
potentially quite useful to someone.

-- 
                                                          - Warp


Post a reply to this message

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