D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [Fwd: Re: [LUG] big list of cool software?]



On Mon, Jul 22, 2002 at 07:00:35PM +0100, kevin bailey wrote:

what do the extended parts of OO get used for - except for writing 
langauges?  i did c++ at college but have mainly worked on database 
based systems since because this is what businesses want.

That's not all business want :)

A classic example is a drawing system. Let's say you have a drawing
canvas and on it you put a bunch of shapes. Let's take the basic
approach; the only one PHP will handle.

Picture = Canvas + *.Ellipse + *.Rectangle + *.Arc + Draw()

Ellipse = (X,Y) + Radius1 + Radius2 + Rotation + DrawMethod()
Rectangle = (X1,Y1) + (X2,Y2) + DrawMethod()
Arc =  (X,Y) + Radius1 + Radius2 + Rotation + From + To  + DrawMethod()
(all of which are fundamental data types)

Each shape has its own data and its own draw method.

In the program, we'd call:

somecanvas = Picture.Draw()

This would probably:

for each e in Ellipses {

   e.DrawMethod(Canvas);
}

for each r in Rectangles {

   r.DrawMethod(Canvas);
}

for each a in Arcs {

   a.DrawMethod(Canvas);
}

return Canvas

##

Now, let's take a "real OO" system.

Picture = 1.Canvas + *.Shape + Draw()

Shape = [virtual]DrawMethod()

Ellipse = isa Shape + (X,Y) + Radius1 + Radius2 + Rotation
Rectangle = isa Shape + (X1,Y1) + (X2,Y2)
Arc =  isa Shape + (X,Y) + Radius1 + Radius2 + Rotation + From + To

Each of these also implements a DrawMethod, as before.

The difference, with proper inheritence and virtual functions is now,
drawing is like this:

somecanvas = Picture.Draw()

This would probably:

for each s in Shapes {

   s.DrawMethod(Canvas);
}

return Canvas

##

No double book keeping, not lists of each type, easy to add a new
type. One method for adding to the liust of shapes, etc. etc.

Proper OO is nice.

Steve

--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly