Liskov substitution principle (LSP ):
A class instance should complete all functions of its superclass instance.
For example, in mathematics, a circle is a special case of an elliptic, but some behavior of an elliptic is also not possessed by a circle in object-oriented systems. For example, the height of an elliptic can be twice the width, but the circle does not.
Demeter rules (SLS ):
In informal terms, this rule assumes that each method should only send messages to a limited number of objects, including: the object as a parameter, indicating the pseudo variable (that is, this) of the current object ), and the direct components of the current object.
For example, we now have a class A that is used to process data from a remote computer. There is a Class B that manages remote computers. A has a method that accepts the parameter B object, object B has a property C for storing the IP address of the remote computer. C can return the IP address D of the remote computer. Object D represents the IP address of object B. Suppose we want to process the data, to determine whether remote computer D is available, we may write
If (B. C. isactive ())
{
//...
}
In this way, it violates the level of detail (PAD), because B. C is neither a parameter nor an attribute of the current object (this. We assume that the IP address of the machine represented by location C is variable, so that once the IP address changes slightly, any subtle changes in Location C will cause errors in the program.