[Tutor] Why Won't My Pizza Fall?

Alan Gauld alan.gauld at btinternet.com
Mon Jan 14 09:18:25 CET 2008


"Ricardo Aráoz" <ricaraoz at gmail.com> wrote

> Anyway Alan, what do you think about Pizza as a class? It has two
> properties, (x, y) that express it's position, but with respect to 
> what?

Any cartesian coordinate system.

> Pizza cannot exist by itself, it has a strong dependency on another
> object that will give context to Pizza.x and Pizza.y and in giving
> context then it would modify Pizza's behavior

Providing context does not necessarily imply modifying core
behaviour.

> happens and where is the floor). So Pizza is tightly coupled with
> another object. Isn't that questionable? I don't have an answer. 
> What do
> you think?

It is coupled in that it receives the x,y from an outside agency.
But it does not depend on that agency once intialised. The
coordinate system could be an 80x24 character display or
a 1024x768 GUI screen or a 40000x60000 virtuyal screen
or a purely conceptual mathematical model. Pizza doesn't
care it just knows where it is now and how to "fall". The only
context it needs is the initial x,y and the dx,dy values that
govern its fall rate.

If some other factor were to determine its behhaviour more
closely - such as determining whether the Pizza was within
the coordinate boundaries or in collision with another Pizza
then that could be implemented via a message protocol.
Thus the context object should respond to some message
from Pizza and in this case the Pizza should hold a reference
to its context manager(probably a screen or grid of some sort).
The context manager is responsible for tracking the objects
being managed, but the objects remain responsible for
managing their own state.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list