On Sun, Sep 28, 2003 at 12:52:40PM +0200, anders thoresson wrote:
: 
:  I wonder if someone can point me to tutorials that uses real PHP examples 
: instead, examples that shows me in a direct way how to use OOP. My biggest 
: trouble right now is what should be the classes and what should be the 
: methods.

Objects should try to model a real thing.  A thing may have properties
(e.g. weight, color, dimensions, temperature, gender, age) and/or states
(e.g. solid/liquid/gas, running/ready/waiting, eating/sleeping/working);
properties are stored in instance variables.  And the thing can do tasks
or have tasks done to them; these tasks are your methods.

Here's a simple exercise you can do: make a "watch" class that models a
real watch.  You can get the current time from a watch; and you can also
set the watch's time.  This class should have 3 methods (i.e. 2 methods
and 1 constructor) and 1 instance variable.  If you use Unix timestamps,
this should be really short (maybe around 10 lines of PHP code).

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to