Head First Design Patterns Ch-1: Design principles

After reading first chapter from Head First Design Patterns book i figured out few good points which should be noted while designing any system in object oriented way which are below:

– identify the aspect of your application that vary and separate the from what stays the same.
  • Take what varies and “encapsulate” it so  it won’t affect the rest of your code.
The result? Fewer unintended consequences from code changes and more flexibility in your systems!

– Program to an interface, not an implementation
  • We will use an interface to represent each behaviour and each implementation of a behaviour will implement one of those interfaces.
– Class relationships: IS-A, HAS-A, IMPLEMENTS
– Favour composition over inheritance (HAS-A)
  • Instead of inheriting it’s behaviour the entity get their behaviour by being composed with the Right behaviour object
  • You can change behaviour at runtime as long as the object you are composing with implements the correct behaviour of interface.
  • Composition is used in many design patterns.
The Strategy Pattern defines a family of algorithms(behaviours), encapsulates each one and make them interchangeable. Strategy let’s the algorithm(behaviour) change independently from the Client that use it.
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

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