Monday 7 May 2007

Strategy Pattern (blog 9)

I found this pattern very interesting as it gives the client to choose their requirment. Strategy pattern helps us in defining family of algorithms and of them can be encapsulated so that they can be interchangeable.
The aim behind the strategy pattern is to make things easier for the implementation and maintenance of methods. It is also possible to use strategy pattern in software design. S
Strategy pattern should be used when
1. you require different versions of algorithms
2. Suppose you have many different classes which are related to each other but they differ from each other in terms of their behaviour. In this case, strategy pattern helps you in configuring a class with one of serveral different behaviours..
Strategy pattern can help us in avoiding the usage of difficult data structures. [1]
Reference:
Raghvendra Singh, accessed 7th May, 2007

4 comments:

Sunny said...

Hi Hani, you are right, it is indeed very interesting. As you mentioned, it enables the client to have its own desired algorithm to run and also allows interchangeability which means that the same class can be used by many other clients as well by just swapping the algorithm that they use.

And the disadvantage that you did not mention is that more objects will be created to host each algorithm and also the application must know all the strategies before hand to be able to make the right choice for algorithm for the client.

Sunny

Gayan lakshitha said...

Hi hani,(GAYAN 372858)
You need to add more in topic of using the stragey pattern in your post.I think one is ir put an object and its behavior are seperated and put into two different classes.

Good work,

Hani said...

thanks sunny and gayan for reading my blog and your useful comments.thanks alot

Ibrahim Thuku said...

hallo,
i was going through your work and i found it intreresting on how you have summarised yourpoint into simple clear sentences. from the strategy pattern blog you have summarised nicely and sunny a fellow student has completed for you what you had left out. good summarizing skilss improves on understanding.
keep up