Tuesday, September 2, 2014

Strategy Pattern

Each type of Duck should implement its own display, so display is an abstract method in parent Duck




What if not all the types of Duck fly, but only a few of them do.
By putting fly in the parent Duck, we are giving ability for all the types of Duck to fly, but only few types of Ducks can fly.

This is to say that the fly behavior is not constant across all types of Ducks. Each type of Duck












You'd have to override fly() and quick() for every new Duck subclass that's ever added to the program ... forever.




Design Principle

Identify the aspects of your application that vary and separate them from what stays the same.
Take what varies and encapsulate it so it won't affect the rest of your code, so that you can alter or extend the parts that vary without affecting those that don't.









No comments:

Post a Comment