课程: Programming Foundations: Design Patterns
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Programming to an interface
- [Instructor] Let's go back to the original duck design and rethink this from the perspective of separating what varies and programming to an interface. To separate what varies, we're going to move the implementations of quack and fly out of the duck class. We're also going to make sure that we're programming to an interface rather than an implementation by using two interfaces, quack behavior and fly behavior. Now let's use these interfaces by implementing some concrete quacking and flying subclasses. For quacking, we'll implement a quack subclass, a squeak subclass, and also a class that doesn't make any sound at all, which we'll call mute. For flying, we'll implement a fly with wings subclass and a fly no way subclass. Obviously, we could've added more concrete implementations to both of these. But for now this is all we need. Now that we have these behaviors in place, we can rework the duck class. To do…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
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 秒
-
-
-
-
-
-
-