课程: Programming Foundations: Design Patterns
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Understanding the decorator pattern
- [Narrator] Now that you're familiar with the decorator pattern, let's take a look at the definition from the Gang of Four catalog. The decorator pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality, and we have a sense of how this design pattern can help us make a flexible design from our coffee example. As you're seeing, the formal definition of a pattern usually describes the role of the pattern, but it doesn't necessarily help us know how to implement it in our own designs. As with all design pattern definitions, we really need to look at a class diagram to get a better sense for how the pattern works. There are two important parts to the decorator pattern. There are the components which are the beverages in our example and the decorators which are the condiments in our example. Starting at the top of this diagram,…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-
-
-