Six principles of design pattern: Civet cat for Prince--the replacement principle of the Richter scale

Source: Internet
Author: User

According to unofficial history legend, that year Song Zhezong most favored concubine is Liudefei. Liudefei, although deeply favored by the emperor, but can not give birth. Liudefei to compete for the Queen's position, to improve their own price, then came up with "borrow pregnant" trick. She intends to lure Song Jinzong by using a maid with a somewhat feminine surname, Lee, beside her. At the time of bathing in the Liudefei, really lucky this Li surname maid, soon this maid on pregnancy, this makes Liudefei also pretend to be pregnant, in fact, maid pregnancy is true, Liudefei just arrange tricks pretend. When the birth of October, the "Two" dragon species have been born. Liudefei took a civet cat for the Prince's despicable means, let the real will li surname maid limbo, but his wish to boarded the dream of the Queen throne.

on today, Liudefei must be an object-oriented master. She understands the "Richter replacement Principle":
-Create "parent class" – Pregnant women, pregnant women have two major characteristics: pregnancy, baby.
-then create an example of two pregnant women: Liudefei and the maid of the surname Li.
-Finally in the run, with their own replacement of the real pregnant woman Lee Maid, successfully deceived the emperor.

The ability to dynamically replace at run time is due to the fact that Liudefei's behavior completely inherits the characteristics of a pregnant woman.

Finally, the definition of the Richter replacement principle is given:

On the Richter scale replacement, LSP (Liskov Substitution Principle), where all references to base classes must be able to transparently use objects of their subclasses. In layman's words, as long as the parent class can appear where subclasses can appear, and the substitution of subclasses will not produce any exceptions.
We know that the three major characteristics of object-oriented language are inheritance, encapsulation, polymorphism, the principle of the Richter substitution is to rely on inheritance, polymorphism, to establish the abstraction, through the abstract establishment of norms, at runtime to replace the specific objects, to ensure the scalability of the system, flexibility.
Often and open closure principle is not abandoned.

Six principles of design pattern: Civet cat for Prince--the replacement principle of the Richter scale

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.