课程: Programming Foundations: Design Patterns
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Using the Decorator pattern
- [Female Instructor] Here's how we implement Starbuzz Coffee using the decorator pattern. Remember, our new design uses a common super class beverage for both the coffees and the decorators. And each decorator is composed with the beverage it is wrapping. We'll start at the top with the beverage class. This is our component super class. It implements a get description method that returns the string unknown beverage. But hopefully the concrete component classes will override this to a better description. And it specifies an abstract method cost that subclasses must implement. Now let's take a look at one of the concrete components. These are the coffees that extend the beverage class. For instance, the dark roast class extends beverage and sets the description string it inherits from beverage to dark roast coffee, so we get a good description of the coffee. Then, dark roast implements the cost method and simply returns 99…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
(已锁定)
Creating chaos with inheritance4 分钟 12 秒
-
(已锁定)
Understanding the open-closed principle2 分钟 49 秒
-
(已锁定)
Extending behavior with composition2 分钟 29 秒
-
(已锁定)
Understanding the decorator pattern2 分钟 23 秒
-
(已锁定)
Using the Decorator pattern5 分钟 6 秒
-
(已锁定)
Challenge: The Decorator pattern40 秒
-
(已锁定)
Solution: The Decorator pattern1 分钟 22 秒
-
(已锁定)
-
-
-