Review
Object-oriented: Automatic loading (__autoload), class constant access (scope resolution operator), static (Properties and methods: Self)
Design mode: Singleton mode (three private one), Factory mode
Object-oriented three main features: encapsulation, inheritance and polymorphism (PHP not supported)
PHP Inheritance: Extends (Object inheritance: Properties and non-private methods) PHP inheritance method overrides
A subclass has a method with the same name as the parent class.
In addition to private properties and methods, the system is always looking for properties and methods in subclasses, but if the corresponding properties and methods are private, then the system must determine the context (class environment) that $this represents, and in which class the private properties and methods of the class are accessed.
Overriding principle: the access to the overridden method must be greater than the permissions of the original method (Open).
PHP Inheritance Chain
A class is not supported in PHP that inherits from more than one parent class.
Multiple inheritance can be implemented in some languages: class A extends B,c (not in PHP)
In PHP, you can implement subclasses to inherit multiple "parent classes" through inheritance chains (chained inheritance).
The use of static in inheritance
Static things belong to classes, classes actually have similar inheritance concepts in structure, so static content can also follow the tradition of inheritance to cross-class use.
Parent keyword
If the parent class's method is overridden in a subclass, then the parent class's method is no longer called, but sometimes a method that requires the parent class is executed, using the parent keyword:
Within the overridden method: Parent:: Method with the same name as the parents class ()
Special class
Sometimes you don't want your own classes to be inherited by others, because inheritance can destroy the structure of a class. Final class
The final class, also called the Ultimate class, refers to a class that is decorated with the final keyword and cannot be inherited by another class.
The final keyword also modifies the method, indicating that the modified method cannot be overridden by the quilt class.
Final class meaning: Can not inherit, prevent class structure from being destroyed abstract class
Some classes can not be instantiated and can only be inherited.
Abstract classes are classes that are decorated with the abstract keyword.
Abstract classes can only be inherited
The abstract keyword can be used on a method, indicating that the current method is an abstract method, and that an abstraction method cannot have a method body (curly braces)
Abstract methods must be implemented by the Quilt class: Override and Add Method body
Abstract methods to implement abstract classes
Inheriting abstract methods: Subclasses must also be abstract classes
A class that has an abstract method must be an abstract class (the class must be displayed using the keyword abstract)
The meaning of abstract classes: Abstract classes are used to standardize the names of methods owned by the following subclasses
If the project is large, it is possible to use an abstract class, and if the project is small or does not require so many specifications, then the abstract class is not used.
An abstract class can have any class member in a normal class, but cannot use a private access modifier qualifier (private)
Interface
The interface is divided into many kinds
Application-based interface: A portal that allows for external use
Data-type interface: A way to standardize the external implementation of certain functions (structure specification) define interfaces
Syntax: interface interface Name {//interface body}
Interface Body
The interface body, also known as an interface member, refers to content that can be defined in an interface.
in an interface, there can be only methods and constants , and the method must be abstract (no abstract keyword required: No method body) and only public adornments.
Interfaces cannot be instantiated, interfaces cannot be "inherited", interfaces can only be implemented: implements implements interfaces
Implement interface values: To implement an interface with a class, you must implement all the abstract methods in the interface.
interface meaning
As with abstract classes, the structure of the underlying class is used to standardize. A more restrictive canonical structure than an abstract class. An interface is a structure that is purely for specification.
Interfaces are used to standardize the entire team and ensure the same structure within different branches of the organization, only when the team is larger and the branches are more numerous. Special use of interfaces
Interfaces can be implemented more than one class can implement multiple interfaces at the same time
Class name implements interface 1, interface 2,... {}
Interfaces can inherit interfaces: interface a extends b{}//b is an interface
Common face questions
1. Is the abstract class A class?
Abstractions should be understood to be classes, but classes that cannot be instantiated. (using the Keyword Class)
2. Does PHP support multiple inheritance? How to simulate?
PHP does not support multiple inheritance, but you can use chained inheritance to simulate the implementation of multiple inheritance.
2. Is the interface not a class? Is the interface not an abstract class?
Interfaces are not classes, interfaces are interface, classes are class; interfaces are not abstract classes
3. Can the interface be inherited?
Interfaces can be implemented only by classes, but interfaces are inherited by interfaces. Common methods related to class
Class_exists: Determines whether a class exists in memory for data judgment before the class is loaded
Interface_exists: Determine if the interface exists
Method_exists: Determines whether a method exists, as long as the method exists, not related to the method of all access modifier qualifiers
Get_class: Get the object class name
Get_parent_class: Gets the name of the parent class, obtains the class name of the ancestor class of the class that corresponds to the current object, and if the ancestor inherits from the other class, it cannot be obtained. (Can only get parent class name)
20150112--abstract class + interface + reload + auto-load mechanism-01