课程: Programming Foundations: Design Patterns
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Solution: The Strategy pattern
(energetic music) - [Narrator] Here's our solution to the challenge. We've pulled out the different ways of sharing into a separate family of classes that implement sharing by texting, sharing by email, and sharing on social media. This is our family of algorithms. We've also added a property to the PhoneCameraApp superclass that will be composed with a strategy that the user selects. Now when the share method is called, the super class is going to delegate sharing to the user's preferred share strategy. So this design allows us to more easily add, change, and remove sharing strategies without have to modify any code in the camera app or any code in the concrete camera app classes.
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
Revisiting inheritance1 分钟 30 秒
-
(已锁定)
Limitations of inheritance4 分钟 18 秒
-
(已锁定)
Trying interfaces2 分钟 28 秒
-
(已锁定)
Get inspiration from design principles3 分钟 37 秒
-
(已锁定)
Programming to an interface1 分钟 32 秒
-
(已锁定)
Applying the principles4 分钟 36 秒
-
(已锁定)
Exploring the strategy pattern1 分钟 59 秒
-
(已锁定)
Why HAS-A is better than IS-A2 分钟 4 秒
-
(已锁定)
Challenge: The Strategy pattern2 分钟
-
(已锁定)
Solution: The Strategy pattern46 秒
-
-
-
-
-
-
-