php array and string manipulation

php array and string manipulation

Abstract class

1. Abstract classes cannot be instantiated

2. The abstract method must be overridden by subclasses

3. If the class contains abstract methods, then the class must be defined as an abstract class, regardless of whether it contains other general methods.

An abstract class usually represents an abstract concept, which provides a starting point for inheritance. When designing a new abstract class, it must be used for inheritance. Therefore, in a hierarchical structure formed by inheritance, the leaf node should be a concrete class. The branch node should be an abstract class.

interface

The interface combines implicit public methods and attributes to encapsulate a set of specific functions. Once the interface is implemented, the class can support all the attributes and members specified by the interface. Declaring an interface is syntactically the same as declaring an abstract class, but it is not allowed to provide the execution mode of any member in the interface. Therefore, the interface cannot be instantiated, cannot have construction methods and fields; cannot have modifiers, cannot declare virtual or static, and the class that implements the interface must implement all the methods and attributes in the interface.

A class can support multiple interfaces, and multiple classes can also support the same interface.

The difference between abstract class and interface

The abstract class can give the realization of some members, but the interface does not contain the realization of the members. The abstract members of the abstract class can be partially realized by the subclasses. The members of the interface need to be fully realized by the realization class. A class can only inherit the abstract class, but it can realize more Interface, etc.

1. a class is an abstraction of an object, an abstract class is an abstraction of a class; an interface is an abstraction of behavior. Interface is the abstraction of the part (behavior) of the class, and the abstract class is the abstraction of the whole class (attributes, fields, methods).

2. If the behavior spans objects of different classes, you can use interfaces; for some similar class objects, use inherited abstract classes.

There is no conflict between implementing interfaces and inheriting abstract classes.

3. From a design perspective, the abstract class discovers common things from the subclass, generalizes the parent class, and then the subclass inherits the parent class, and the interface does not know the existence of the subclass at all, and how to implement the method is not yet confirmed , Predefined.

Reference: https://cloud.tencent.com/developer/article/1053187 php array and string operations-Cloud + Community-Tencent Cloud