课程: Programming Foundations: Design Patterns

今天就学习课程吧!

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

Applying the principles

Applying the principles

- [Instructor] Let's take a look at some sample code to demonstrate how we implement our new design and pull out and separate what varies in our code. For this sample code, we'll just Java. We'll be showing just a few snippets of code. To see the full working examples, download the exercise files. We'll begin by looking at the flying and quacking behaviors we've pulled out from the ducks. Recall one of the design principles we've talked about. Program to an interface, not an implementation. For both our behaviors, we'll define interfaces that all behaviors will implement. So, all fly behaviors will implement the flyBehavior interface. For example, we might implement a FlyWithWings behavior that implements regular flying and a FlyNoWay behavior that implements no flying for a duck that can't fly. Likewise all quack behaviors will implement the quack behavior interface. We might implement quacking behaviors like…

内容