|
Posted by Colin Fine on 10/13/05 22:15
Samuel wrote:
> In general, OOP is more or less what your example shows. The class
> defines what the object is and can do, while the object actually *is*
> something (an instance of the class) and *does* something. See if this
> pseudocode helps...
>
>
> Class Dog
> {
> var race;
> var food_it_likes;
>
> function Bark
> {
> ...
> }
>
> function Poop
> {
> ...
> }
>
> } //End Dog Class
>
>
> //You have just defined what a dog is and can do, so that you can have
> multiple dogs doing stuff. Then, in your program...
>
> Dog Vincent;
> Dog Toby;
>
> Toby.race = "Scottish Terrier";
> Toby.food_it_likes = "Tasty Chicken";
> Vincent.race = "Chiuaua";
> Vincent.food_it_likes = "Human Flesh";
>
> Vincent.Bark;
> Toby.Poop;
>
> //You now *actually* have two dogs who can bark and poop. One is
> barking (Vincent the scary assasin little chiuaua), and the other is
> pooping (Toby the elegant black Scottish).
>
> Greetings
>
This is obviously not PHP syntax (Samuel even says it's pseudocode), but
it could easily mislead people into a mistake that I kept making when I
started:
The PHP for some of those lines might be
$Vincent->race = "Chihuahua";
but
$Vincent->Bark();
If you leave out the parens, it's an (undeclared) property (variable)
not a method (function).
Colin
Navigation:
[Reply to this message]
|