Favour composition over inheritance

I am reading Head First Design Pattern again and want to summarise a few things I need to remember. I forget things so easily.

The Strategy Pattern defines a family of algorithms, encapsulate each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients from using it.

Abstract class Duck has MallardDuck and RubberDuck.Duck has two behaviours, IQuackBehaviour and IFlyBehaviour. The two behaviours vary, depending on the type of duck. IQuackBehaviour has Quack, MuteQuack, and Squeak. IFlyBehaviour has FlyNoWay, FlyWithWings, and FlyRocketPowered.

Favour composition over inheritance

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s