The decorator mode of the big talk design pattern

Source: Internet
Author: User

Decorator mode enables you to wrap objects one layer at a level by using inheritance.

1,person is a decorated object, in the decorator pattern class diagram, all classes inherit from the person class. The person class has a show method that shows which costumes for the person object are decorated. By inheritance, all classes have a show method, so when a person wears some kind of costume, it is possible to invoke the Show method of the costume. When there are no costumes to decorate the person, the execution of the Show method represents the most original.

2, the abstract costume class inherits from the person class, although from the natural concept, the dress is not human. However, inheritance is still used here. One reason is that this kind of abstract clothing class has a show method, so that the specific clothing class also has a show method, when using a specific dress to decorate the object, you can use the Show method of the costume show.

3, although the abstract costume class inherits the person class, it also has a property of the person class, which is used to specify which object to decorate for each specific costume class. Because this property is person type, so class A dress can decorate class B dress, B dress can decorate C class dress, ... The final class N costumes have the person object (in turn).

4, since each specific costume inherits the show method from the parent class, in the Show method, each specific costume has a personal decoration, and then calls the parent's decorations (the so-called layer-by-layer wrapper).

The decorator mode of the big talk design pattern

Related Article

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.