The seventh chapter (1) Object-oriented approach-object-oriented concept
What is a class: the process of composing an object is called a class.
What is an object: A class consisting of something called an object.
The relationship between a class and an object: objects are grouped by classes, and classes have objects.
What is a member property: Defines a member static description. such as: person's name, sex, height, weight ...
What is a member method: defines a dynamic description of a member. Can achieve some of the functions such as: People can eat, walk, drive, talk ...
How to abstract a class:
Class name such as: human
{
Member properties: Name, height, weight ...
Member method: Walk, Talk, eat, drive ...
}
Examples:
class keyword Person class name first letter to capitalize
{
Member properties
var keyword $name; name
var $age; age
var $sex, sex ...
Member Methods
function keyword say ()
{echo "I'm Talking";}
function Run ()
{echo "I'm Walking";}
Function Eat ()
{echo "I'm Eating";}
}
To produce an instantiated object:
$P 1=new keyword person class name;
$P 2=new person;
The seventh chapter (3) Object-oriented detailed _ Object instantiation and use
How to instantiate an object
Example Description:
Class Ren
{
var $xingming;
var $nianling;
var $xingbie;
var $shouji;
function Shuohua ()
{echo "I'm Talking <br>";}
function Zoulu ()
{echo "I'm walking <br>";}
function Chifan ()
{echo "I'm eating <br>";}
}
Class Shouji
{
var $pinpai;
var $yanse;
var $chiceng;
function Dadianhua ()
{}
function Jiedianhua ()
{}
function Faxinxi ($ren, $xinxi)
{$ren->shouji->shouxinxi ($xinxi);}
function Shouxinxi ($xinxi)
{echo "Access info". $xinxi. " <br> ";}
}
instantiated. Person:
$r 1=new Ren (); $r 2=new Ren (); $r 3=new Ren ();
instantiated. Person's name:
$r 1->xingming= "John"; $r 2->xingming= "Dick"; $r 3->xingming= "Harry";
instantiated. Mobile Phone:
$s 1=new Shouji (); $s 2=new Shouji (); $s 3=new Shouji ();
instantiated. Human Mobile:
$r 1->shouji= $s 1; $r 2->shouji= $s 2; $r 3->shouji= $s 3;
instantiated. Human Hair message:
$r 1->shouji->faxinxi ($r 2, "Hello");
Output: Receiving information Hello