OC's Richter Replacement principle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.