1. The Richter replacement principle. Lsp
The subclass object can replace the location of the parent class object, and the function of the program is unaffected.
Why?
1). The pointer is a 1 parent class type, but we do give the address of the pointer 1 subclass object.
This is certainly possible, because you want 1 parent class objects, and I gave you a sub-class object.
A subclass is a parent class.
2). Because the member subclasses in the parent class have. There will be more than one less.
Therefore, the function of the program is not affected.
2. The form of the Richter replacement principle:
When 1 parent-class pointers point to 1 subclass objects. Here is the Richter replacement principle.
3. What are the benefits of LSP?
1). 1 pointers can store not only the address of this class of objects, but also the address of the child class object.
2). If the type of 1 pointers is of type nsobject. Whoa, whoa. Then the pointer can store the address of any OC object.
The types learned in the C language are not OC objects.
So, a pointer of type NSObject, we call the universal pointer.
3). If the element type of an array is the 1 parent class pointer type. Then this array can store either this class object or the Subclass object.
4). If the element type of an array is of type nsobject*,
Then it means that the array can store arbitrary OC objects.
5). If you find that the parameters of the 1 methods are 1 parent class objects, the arguments can be 1 parent class objects or 1 subclass objects.
4. Limitations of LSP.
When the 1-parent pointer points to 1 child-class objects
The parent class member in this subclass object can be accessed only through this parent pointer. Members that are unique to the subclass cannot be accessed.
OC's Richter Replacement principle