1. What is object-oriented? Object-oriented programming is a computer programming architecture, and the basic principle of OOP is that computer programs are composed of a single unit or object that can be used by subroutines, and OOP achieves the three goals of software engineering: reusability, flexibility and extensibility. 2. The relationship between classes and objects is like the relationship between the mold and the casting, the result of the instantiation of the class is the object, and the abstract of the object is the class, and the class describes a set of objects that have the same attributes (attributes) and the same behavior. For example, the relationship between class and object, like you go to Zhongguancun to buy PC (computer), you want to buy is to assemble PC parts. You have a configuration sheet, and all the parts you want to buy are on this configuration sheet. However, this configuration sheet you can think of it as a class, you follow the configuration of the parts of the first part of the computer is the object, you follow the configuration of a single assembly of 10 computers then there is an object, you make a change to one of the computers, the configuration will not change, if you make changes to the configuration order 10 computers will change, This is the relationship between the class and the object (the instantiation of the class is the object). 3. A class's conceptual class is a collection of objects with the same properties and services. 4. Object Concept object is an entity which is used to describe objective things in system, it is a basic unit of composing system. An object consists of a set of properties and a set of services that operate on that set of properties. 5. What is object-oriented programming? You abstract each individual function module into a class, forming an object, and there are multiple objects that make up the system, which can interact with each other by receiving information, processing data and sending information to other objects, and so on. constitutes an object-oriented program. Note: The unit of an object-oriented program is an object. 6, how to abstract a class? How to instantiate an object? How do I use Members in an object?
1.
Class Name {//Use the keyword class followed by the name you want, plus a pair of curly braces, so that the structure of a struct is defined}2.$DB = new class name; Use the new keyword to generate an object. A class can instantiate multiple objects, each of which is independent. Each object contains the properties and methods of the class. 3. to access the form of a member in an object outside the objectTo access members of an object, you use a special operator, "-" to accomplish access to the object members. Access object properties: $DB properties (); &NBS P access to object methods: $db-Way ();  &NBSP Inside the object to access the form of members in the object access to object properties: $this-Properties (); &nbs P To access the object method: $this-, Method (), 7, constructor &N Bsp 1. The constructor can accept parameters and be able to assign values to object properties when the object is created. 2. Constructors can call class methods or other functions. 3. Constructors can call constructors of other classes. function __construct () { & nbsp parent::__construct ()//Call the constructor of the parent class; &NBS P classname::__construct ()//Call the constructors of other classes classname is the class name } &NBsp destructors 1, destructors are calls that are automatically called when objects are destroyed and cannot be displayed. 2, destructors can not take parameters. When the object is unset (); The destructor is called when it is destroyed. 8, packaging 1, encapsulation is one of the three object-oriented features, encapsulation is the object's properties and services into a separate unit, and as far as possible to conceal the internal details of the object, contains two meanings: 1, Combine all the attributes of an object with all services to form an indivisible independent unit (i.e. object); 2, the information is concealed, as far as possible to hide the internal details of the object, to form a boundary (or form a barrier), only a limited external interface to make it with the external connection. The principles of encapsulation require that parts outside the object not be arbitrarily accessible to the object's internal data (attributes), thus effectively avoiding the "cross-infection" of external errors on objects, Make errors localized, reducing the difficulty of error-checking and troubleshooting. 9, __set (), __get (), __isset (), __unset () Four methods of application 1, __set () Functions: Automatic execution, for The private properties of the class are assigned. There are two parameters (property name, assign value to attribute); 2, __get () function: Auto Execute, get private property of class outside class, have one parameter (property name); 3 , __isset () function: Determines whether a variable exists in a class, exists return True, otherwise returns false, if the variable in the class is private, it is executed automatically by adding a __isset () method to the class. 4, __unset () function: Deletes a variable in a class, if the variable in the class is private, to be executed automatically by adding a __unset () method to the class. 10. Inheritance of class Inheritance is an aspect of the three important features of object-oriented, and he is to create a new derived class that inherits the data kernel function from one or more previously defined classes. There is no multiple inheritance in PHP and Java, only single inheritance, that is, a class can only inherit data directly from a class, which is a single inheritance. 11. Override the method in the parent class in the subclass. The methods of the parent class to be overwritten are added with a bit of their own functionality, and there are two ways to implement the method of calling the parent class overridden in a subclass 1, "Class Name:: Method Name ()" Call overridden method in parent class 2, "Parent:: Method Name ()" Call the overridden method in the parent class The two methods can be implemented, but instead of using the class name, you should use pare Nt,parent refers to the subclass in the extends declaration of the parent class, so that you can avoid using the name of the parent class in many places, as well as in the implementation of the process if you want to modify, just modify the part of the extends declaration. NOTE: The access rights of a method in a subclass must not be less than the access of the parent class's overridden method, that is, must be above or equal to the access rights of the parent class method.  12, Access type (public (common, default), protected (protected), Private (private)) Three kinds of 1, publicly communal modifier There are no restrictions on members, properties, methods, and access in the class, and all external members can access them. 2, protected protected modifiers modified classes, members, properties, methods in a class cannot be accessed by code outside the class. However, there are access rights to the subclass. &NBsp 3, private private modifier defined member, for all members of the same class is accessible, external is not access, for this subclass can not visit & nbsp , &NB SP; Ask the member who is defined private. Applications for 13, final keywords Final keywords can only be used to define class and definition methods, and cannot use final to define member properties, because final is the meaning of constants, We define constants in PHP5 using the Define () function, so we do not make final define member properties. A class that is defined by the final cannot be inherited, and a method that is defined by the final cannot be overridden by a quilt class. Use of the 14, static, and Const keywords (self::) static members are able to restrict external access, and static members are instances of classes that are not part of any object. Static members are shared by each instance object of this class, and static methods that use objects without access to static members classes can only access static properties of the class. The static method is not called with the object, but instead uses the class name to access to access other static members in a static method we are using a special class "self" The class that represents this static method that is: Self:: member properties Const is a keyword that defines constants access methods class names:: Properties self:: Properties Note: Do not add $ symbol 15, __tostring application &NBSP Defining the __tostring () method in a class can directly output an object. 16, __call Handling call errors 17, abstract classes and abstract methods 1, abstract methods & nbsp The method of no method body defined in the class is an abstract method, the so-called no method body refers to the method declaration when there is no curly braces and the contents of it, but directly at the declaration of the method name after the end of the semicolon, and in the Declaration of abstract methods also add a keyword " Abstract "to decorate For example: Abstract function fun1 ();
2、抽象类
As long as there is one method in a class that is abstract, the class is defined as an abstract class, and the abstract class is also decorated with the "abstract" keyword, and there can be no abstract method and member property in the abstract class, but as long as there is a method that is abstract, the class must be declared as an abstract class, using " Abstract "to modify
Simple introduction to Object-oriented