Thursday 3 May 2007

Strategy Design Pattern

I missed this lecture as I was attending hospital appoinment. Information which I have gathered from lecturer's notes and a bit of self stuyding did however allow me to outline my understanding as below:-

Strategy Pattern is basically used to achieve different behaviours. In simple terms, an object and its behaviour are separated into two different classes. Each behaviour encapsulated into its own class and it's called Strategy.[1]

What is the advantage of using Strategy Pattern?

  1. It is much simpler to keep track of different behaviours required from an object as separate classes will be created.
  2. Any amendements need to be made on the behaviour of an object can be achieved quickly as you will keep track of those classes.
  3. In some cases, you will come across of several objects that are similar but different in behaviour. Therefore, using Strategy Pattern becomes very useful.
  4. It is much easier to make an extension on the object with new behaviours without recoding the application.
  5. Using this patterns also means eliminating the need of many conditional statements.

Besides the advantages, I think one must know also know the different strategies available in order to reduce creating of unnessary startegies. If the knowledge is lacking than one might end up creating too many classes which can create problems of maintaining them.

Is Strategy Design Pattern the best to be used?

Well, I think that every pattern has it own uniqueness and is designed to address a specific issue.

---------------------------------------------------------------------------------------------------

Reference - Web Link

[1] http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/StrategyPattern.htm

2 comments:

Gayan lakshitha said...

Hi (gayan-372858)

I bit of confusing about your explanation,achiving different behaviors objects and classes.
I think if you can explain with partcipants of the strategy pattern,this would be more valuble article.

stephen said...

hi, your explanation about strategy pattern is very clear and quite understandable to meand it has a good structure.
If you can add some participant and their responsibility this would be more understandable