Join Elisabeth Robson for an in-depth discussion in this video Programming to an interface, part of Programming Foundations: Design Patterns.
…So at this point, you've made a couple attempts to design a duck simulator.…And we haven't come up with a good design by using either inheritance or interfaces.…So, how do we design something for our ducks?…Well, we're going to follow the design principle, encapsulate what varies.…And begin by determining the parts of our design that either vary or change.…To do that, let's check out the duck class diagram again.…Now, we know that quack varies, because some ducks quack,…some squeak, and some make no sounds at all.…And in the future it seems likely there'll be other variants of quacking as well.…
Fly also varies across the subclasses.…Some ducks fly, and some don't, and…perhaps some ducks even fly in different ways.…Swim however, so far seems to be a constant and doesn't change.…And display is implemented already by each individual duck by design.…Okay, so we've identified…what varies. Now what?…Well we're going to introduce another design principle.…Now this may seem contradictory.…Didn't we just do this, and it didn't work.…
Released
12/13/2013- What are design patterns?
- Encapsulating code that varies with the strategy pattern
- Setting behavior dynamically
- Implementing the observer pattern
- Creating chaos with inheritance
- Extending behavior with composition
- Dealing with multithreading and the singleton pattern
- Revising the design for a state machine
- Encapsulating iteration with the collection pattern
- Encapsulating object creation with the factory method pattern
Skill Level Intermediate
Duration
Views
Q: How do I import the exercise files in Eclipse?



Related Courses
-
Introduction
-
Welcome1m 1s
-
Using the exercise files1m 53s
-
-
1. Design Patterns
-
Using design patterns1m 38s
-
2. The Strategy Pattern
-
Programming to an interface3m 13s
-
Setting behavior dynamically4m 41s
-
3. The Observer Pattern
-
4. The Decorator Pattern
-
Using java.io decorators1m 39s
-
5. The Singleton Pattern
-
Dealing with multithreading1m 31s
-
6. The State Pattern
-
What is a state machine?3m 46s
-
-
7. The Collection Pattern
-
Encapsulating iteration1m 3s
-
-
8. Factories
-
Conclusion
-
Additional resources2m 49s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Programming to an interface