课程: Programming Foundations: Design Patterns

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

Trying interfaces

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.…

内容