Alex Ferguson wrote:
>
> Kevin Atkinson:
> > You have a collection of Shapes. Some of these shapes are circles,
> > however, others are rectangle. Occasionally you will need to extract
> > these specific shapes form the collection of generic shapes as there is no
> > way to find the length and width of a generic shape, only its area and
> > circumference. So I need to cast the objects in shapes that are *really*
> > rectangles back up to rectangles.
> >
> > 1) test for the true type of the object
> > 2) cast it back up to its true type
>
> There's no need for a 'cast' here, as Shape can be represented as a
> class. The trickier part is putting different types into a heterogenous
> collection, and then manipulating according to their _individual_ types.
> Unless you want to restrict yourself to a particular set of possible
> types (in which case it's straightforward, anyway), this seems to me
> like it _is_ a case of dynamic programming.
Yes but it is ALSO a case of typical things one does with OO. Except
with OO it is very natural as you just stick them all into a container
of Shapes. When you need to access the identical type of an object you
use simply case up once you are sure what the REAL type of the object
is. Also in OO you can
have a class heritage like this.
Shape
Circler
Oval
Circle
Polygon
Now than suppose the Circler has a method to find the maxim and minimum
radius of its shape. Now you have a collection of Shapes. For all
those that are Circler you would like to find this information. In
these situation it is NOT necessary to recover the complete type of the
object, but merely to cast it up one level to Circler so that you can
find the this information. Can dynamic programming handle this? And
how?
> > > I'm aware that Haskell doesn't precisely ape that sorts of 'OOP
> > > style' that the likes of C++ admits What I've yet to see is any
> > > argument that this is anything other than the wisest possible decision...
>
> > And by this you mean...
>
> That C++ has a very poor type system.
You are going to have to justify it as I thing C++ and Java has a VERY
good type system minus the implicit typing system. In fact I *like* the
C++ typeing system better than I do Haskell's in many cases.
Do you not like OO at all?
--
Kevin Atkinson
[EMAIL PROTECTED]
http://metalab.unc.edu/kevina/