Richter six principles of object-oriented substitution principle

         This is my object-oriented prior to the 6 major principles of learning notes, which replaced the principle of Leeb lack a deep understanding, https://blog.51cto.com/zhangzhao/2396810 .

         According to the information Baidu Encyclopedia, Richter substitution principle is defined as: Liskov in 1987 proposed a principle of succession of " Inheritance Should the any of Ensure that proved the About Property Also holds for subtype supertype Objects Objects. -" Inheritance must ensure ultra " class owned properties are still set up in the subclass. "that is, when an instance of a subclass should be able to replace any instance of its superclass, it has between them is-a relationship.

         Simply put, when to replace its base class subclass, the behavior of no change.

         This requires:

         1. Subclasses may implement the abstract parent class method, but the method of non-abstract parent class can not be rewritten. (Where necessary to distinguish the concept of rewriting and heavy rewriting refer to the same function name, or the same signature function of the parameter type; the same function name is overloaded, or that different parameters of the signature function type, object-oriented languages polymorphism will automatically match the most appropriate function based on the type of argument passed at runtime calls)

         2. subclass can add their own features.

         3. Pre-overload conditions when the parent process, process subclass ( parameter ) input parameters than the parent class method more relaxed. This is because if the parameters of the subclass method is smaller, then call the function when running, might first call overloaded function subclass, which is contrary to the Richter substitution principle.

         4. The output method of the parent class when overloaded ( return value ) can be reduced.


Guess you like

Origin blog.51cto.com/zhangzhao/2409513