PHP Learning-Object-oriented 1, what is an object
Everything that can be abstracted is the object of all things in the world. Like flowers, grass. The "concept" that is not visible is an object.
2, the basic composition of the object
A. Properties. The description of the object.
B. Methods. The behavior of the object.
Example: NBA stars can play basketball. The star's height and weight are his attributes, and playing basketball is the way it is.
3, the characteristics of the object
A. Uniqueness, every object is unique.
B. The object is a particular transaction and he has a certain function.
C. objects can be reused.
4. Object-oriented Essence
Object-oriented is to store the problems that need to be solved in the way of the objects in the life.
-Properties
-Method
Enjoy the interaction directly through the call to the method
-Method
5, the basic idea of object-oriented.
To describe everything through objects.
A. Identify the object.
-any entity can be recognized as an object.
B. Identifying the properties of an object
-The data stored on the object's surface is considered to be a property
-For different business logic, focus on the data stored in different objects is also different
C. Identifying the behavior of an object
-Changes to the object's own property data
-Object and external interaction
Summary: Identifies an entity as an object, describing its characteristics through attributes, describing its behavior to describe his function.
6. Object-Oriented Basic principles
A. The inside of the object is high cohesion
-the object is only responsible for a specific function
-All object-related content will be encapsulated inside, in the form of attributes and methods
B. The object is low-coupling to the outside
-The external world can see some properties of the object.
-The outside world can see certain things about objects.
Summary: Cohesion poly, low coupling
7, the basic concept of object-oriented
A. Class
-Birds of a feather, classify objects with similar characteristics in a class
-Classes define these similar objects to have the same properties and methods
-A class is a description of a similar object, known as the definition of a class, as a blueprint or prototype of that class object.
-The object of the class is called an instance of the class.
-Class properties and methods are called Class members
B. Instantiation of a class
Instantiation of a Class (instantiate) defines an object of a class through a class
C. Instantiation of classes and classes
-Create a class
<?phpclass nbaplayer {public $name = "Jordan"; Public Function Run () { echo "running\n"; }} $jordan = new Nbaplayer (); Echo $jordan->name. " \ n "; Echo $jordan->run ();
D. Constructors
The default constructor is called when the object is created.
__construct () Construction method
$this Pseudo-Variable
<?PHPclassNbaplayer { Public$name; function __construct () {$ This->name ="Jordan"; Echo"create NBA players \ n"; } Publicfunction Run () {echo"running\n"; }} $jordan=NewNbaplayer (); Echo $jordan->name."\ n"; Echo $jordan->run ();
E. Destructors
Destructors are executed when all the programs in the process are executed.
destructor intervention, which will be executed after the object is set to empty
<?PHPclassNbaplayer { Public$name; function __construct () {$ This->name ="Jordan"; Echo"create NBA players \ n"; } Publicfunction Run () {echo"running\n"; } function __destruct () {echo"destructors are running \ n"; }} $jordan=NewNbaplayer (); Echo $jordan->name."\ n"; Echo $jordan-run ();//$jordan = null;Echo"program end \ n";
PHP Learning-Object oriented