Php object-oriented explanation _ encapsulation. Next we will explain php object-oriented and encapsulation with examples and tutorials, as well as various encapsulation declarations. Chapter 7 (5) object-oriented explanation _ encapsulation below we will explain through examples and tutorials php object-oriented and encapsulation, and declarations of various packages.
Chapter 7 (5) object-oriented explanation _ encapsulation
Next we will explain php object-oriented and encapsulation with examples and tutorials, as well as various encapsulation declarations.
Encapsulation: encapsulates the internal attributes or methods of an object in its own object and can be used or accessed within the object, however, the encapsulated members cannot be used in external objects or other objects.
Keyword used for encapsulation: private
Encapsulation:
1. combine all attributes of an object with all methods to form an inseparable and independent unit (object ).
2. information hiding, that is, hiding internal details as much as possible to form a boundary (or a barrier) for external entities, and retaining only limited external interfaces so that they have a relationship with external entities.
Chapter 7 (6) object-oriented explanation _ four common methods used in Encapsulation
A function with "_" is automatically called at a certain time.
_ Get (attribute name) calls the _ get method when calling a private attribute directly.
_ Set (1. attribute name 2. attribute value) calls the _ set method when assigning values to private attributes directly.
When _ isset (attribute name) is used to determine whether a private attribute exists in an object, the _ isset method is called.
When _ unset (attribute name) is used to delete private attributes of an object, the _ unset method is called.
Chapter 7 (7) object-oriented explanation _ inheritance
Class inheritance: inheritance refers to the extension of the original class.
New extension subclass: 1. class 2. original parent class name 3. extends inheritance keyword 4. New subclass name.
Class inheritance inherits all content in the parent class to the subclass, except for private attributes and methods.
Chapter 7 (8) object-oriented explanation _ method coverage and access
Method overloading: The method name must be the same as that of the parent class. to call all content of a method of the parent class, you can use the keyword pr in the subclass method] arent :: for example, only the part called will be overwritten.
Access type:
Private can only be accessed in this class.
Protected protection can only be accessed in this class and subclass.
Public is unrestricted. in this class, sub-classes and external entities can be accessed.
Chapter 7 (9) object-oriented explanation _ common final, static, and const keywords
Final: can only be used to define classes and methods.
Purpose: classes defined using final cannot be inherited.
Methods defined using final cannot be overwritten by heavy loads.
Static: convert attributes and methods to static ones.
Static can modify attributes or methods.
Non-static members cannot be used in static declaration.
The role of static is to declare it only once in the class. all objects generated by this class have static modified attributes and methods, but the memory is not used repeatedly in the memory, memory can be effectively saved.
To access static attributes or methods, use the class name: defined attributes or methods, or use the felf: defined attributes or methods for access. objects cannot be accessed directly.
The function of const is to define the member attribute as a constant in the class.
Const can only modify attributes.
Const can only be an initial value when it is declared.
Use const to declare attributes without adding $.
To access a const defined attribute, use the class name: defined attribute for access. the object cannot be accessed directly.
Object-oriented and encapsulation, as well as declarations of various packages. Chapter 7 (5) object-oriented explanation _ encapsulation The following describes examples and tutorials...