other oo code
class Cat {
function miau() {
print "miau";
}
};
class Dog {
function wuff() {
print "wuff";
}
};
function printTheRightSound($obj) {
if ($obj instanceof Cat) {
$obj->miau();
} else if ($obj instanceof Dog) {
$obj->wuff();
} else {
print "Error: Passed wrong kind object";
}
print "\n";
}
printTheRightSound(new Cat());
printTheRightSound(new Dog());
//end class
the output is
miau
wuff
Inheritance is performed by using the [extends]
keyword :
class Child extends Parent {
//....
}
This how you would rewrite the previous example
using inheritance :
class Animal {
function makeSound() {
print "Error : This Method should be re-
implemented ins the children";
}
}
class Cat extends Animal {
function makeSound() {
print "miau";
}
}
class Dog extends Animal {
function makeSound() {
print "wuff";
}
}
function printTheRightSound($obj) {
if ($obj instanceof Animal) {
$obj->makeSound();
} else {
print "Error : Passed wrong kind of object";
}
print "\n";
}
printTheRightSound(new Cat());
printTheRightSound(new Dog());
\\end class
THe output is
miau
wuff
and this is the summary that i read its really
cute
"if youre new to PHP but have written code in
object oriented language,
youll probably not understand how people managed
to write object oriented code until now.
if youve writeen object oriented code in PHP4,
you were probably just dying for these new
features"
so what if im really new to object oriented
language.
itll probably i can never understand what should
i do with it.
i read and read and im done with this im off.
i peek in chapter 4 and its an advanced
OOP.....okay !-_-.
i think i need codes that written using OOP
techinque and lots of them so i can get the hang
of it.
in chapter 5 itll be Web Application.
Subscribe to:
Post Comments (Atom)
Starting to Learn Wordpress
I'm gonna start learning wordpress again. I know it's been a while and I'm using Blogger to write everything. I don't know...
-
Well if you don’t know what is Yii Framework. I recommend just go to the main site http://www.yiiframework.com And then http://www.yiiframe...
-
Read the first Part :: Contain the database and basic creating / generating models / crud CJUIDIALOG In these part 2 I will concentra...
-
im currently doing project using PHP 5 and MSSQL SERVER 2005. they use different server. one for web server and the other one is for Databas...
No comments:
Post a Comment