Basic model: (Java,c#,scala)
- Interface, class
- Interfaces can inherit multiple interfaces
- Class can implement multiple interfaces
- Class can inherit only one parent class
Extended model One: Static extension (C#,swift)
- Static scaling is usually a behavior later in the project.
- Static extensions are for specific types and are poorly reusable.
- Extension can extend a class to add a new method to the class.
Extended model Two: Dynamic combination (Scala)
- Trait is similar to an interface with all or part implementations.
- The design of trait is a definite design behavior in the early stage of the project.
- Trait is a standalone structure that is designed to support reuse.
- When declaring a class, trait can be statically mixed into the definition of a class.
- When instantiating a class, trait can be dynamically mixed into an instance of a class.
- Prior to trait, because the implementation of multiple inheritance is not supported, if a class is to use the functionality of other classes, it is necessary to instantiate an instance of another class, which is equivalent to dynamically combining the functions of two classes during the run. After using trait, you can combine the code in a declarative form so that the written code is more readable and can be found if there is a problem in the compilation phase.
The model of object-oriented static language