Strategy Pattern

light111Design Pattern: Strategy 

While designing application, if there are some aspects of the code that changes with new requirements, so this behavior needs to be pulled out and separated from all other aspects that doesn’t change. The varying part may be encapsulated and later it can be altered or extended without affecting the other. 


To make things flexible, it is better to decide the behavior at run time and is possible with interface i.e programming to the Super Type . The declared variable type usually abstract class or interface and in run time any concrete class implementation of the super type can be assigned.


Inheritance is not always good. In stead of using inheritance many time the behavior of the system can be splited into multiple classes and all these classes can be used to result a composition. Creating a system with composition provides a lot many flexibility. 




Leave a Reply

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

You are commenting using your 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 )

Connecting to %s