abalfazl hossein wrote:...still can not understadn how strategy pattern works...
I'm giving a business example using different ways of calculating interest rates. Interest rates can be calculated using a give number of days in a month and a given number of days in a years, such as 30/360, 30/364, and 30/365. If we put these different calculations into different objects we might first create an abstract super class name InterestCalculation and then create the following subclasses: InterestCalculation30/360, InterestCalculation30/364, and InterestCalculation30/365. Now we can design a loan object that has a field to hold an object of type InterestCalculation which will handled calculating the interest of the loan. Of course different loans might take use different interest calcualtions. To handle this we just plug-in the correct subclass instance of InterestCalculation into the instance of a loan. If we didn't use the Strategy Pattern then we would probably have to have some type of big IF/ELSE IF statement in our loan class to handle the different calculations. Any time you see a number of If/Else If statements in an object it is probably in need of the Strategy pattern.
Ran