课程: Programming Foundations: Design Patterns
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Trying interfaces
- [Instructor] Now if you're a well-schooled Java developer, you might be saying, hey, let's use interfaces instead. You might remember that an interface defines the methods an object must implement in order to be a particular type. For instance, if a duck implements a flyable interface with one method fly, then duck must implement the method fly to be considered the flyable type. So interfaces allow different classes to share similarities like ducks sharing a fly behavior. Interfaces also allow for having two classes that are alike, but don't have the same behavior, for some ducks being able to fly and some not. So interfaces actually sound perfect for our design. Let's rework our duck interfaces and see how well this works out. We'll begin by creating two interfaces, flyable and quackable, if I'm a duck and I fly, I implement the flyable interface, and if I'm a duck and I quack, I implement the quackable interface.…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
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 秒
-
-
-
-
-
-
-