Decorator mode in Android design mode and android Design Mode

Source: Internet
Author: User

Decorator mode in Android design mode and android Design Mode

Decorator mode definition: dynamically attaches responsibility to objects. To expand the functionality, the decorator provides an alternative solution that is more flexible than inheritance.

Design Principle: classes should be open to extensions and closed to modifications

In Java, IO classes use the decoration all mode.



Code: http://download.csdn.net/detail/deng0zhaotai/7964311


Decorator mode example in Design Mode

The Decorator dynamically adds actions to objects.
Here, DarkRoast, Mocha, and Whip all implement the Decorator of the Beverage interface.
Beverage beverage2 = new DarkRoast (); // beverage2 is DarkRoast
Beverage2 = new Mocha (beverage2); // adds Mocha behavior to beverage2
Beverage2 = new Mocha (beverage2); // adds Mocha behavior to beverage2
Beverage2 = new Whip (beverage2); // Add Whip to beverage2
Let's look at the specific logic.
It should be that the cost () method of each Decorator calls the cost () of Decoratee before calling the additional behavior.

In Java, there are 23 design patterns. Which of the following are used in Android?

The so-called mode is actually a common idea. After you get familiar with it, you won't even consider what it is. There are more than 23 design patterns.
 

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.