C # object-oriented review> 2015.12.23,
First, we need to know the three features of object-oriented
In program development, it can be understood as method encapsulation of Common Code, class encapsulation of common methods.
The benefits of doing so are:
First, reduce code redundancy and make the code more organized.
Second, you do not need to know how the method is implemented at the underlying layer. You only need to know how to call the method.
Inheritance is used to solve code redundancy between classes. Generic attributes and functions are written to the parent class. Child classes inherit from the parent class and inherit from all attributes and functions of the parent class, inheritance supports inheritance and interface inheritance.
Consider different subclass objects as parent classes to avoid the differences between all subclasses and implement common code to adapt to constant changes.
Next, we need to understand the five features of object-oriented
- Single Responsibility Principle: an object should contain only one single responsibility and fully encapsulate this responsibility in a class. If a class is encapsulated with excessive responsibilities, these responsibilities interfere with each other during concurrent execution.
- Open and closed principle: the application is extended and the code is modified and closed during development.
- Dependency inversion principle: High-level modules should not directly depend on lower-level modules. The correct method should be dependency abstraction.
- Rys replacement principle: Child classes can be replaced with parent classes.
- Interface isolation principle: the client should not rely on interfaces that it does not need. Otherwise, code will be bloated and redundant.