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.