المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : The strategy Pattern: a recurring problem



C# Programming
08-23-2010, 11:51 AM
Hi,
Each time I try to sue the Strategy pattern, the concrete strategy have difference parameters.
For example the Strategy method could be a "double getprice()"
and a concreta class could need a matrix of interest rates, another classes a series of earning, other volatility numerbers and so on.

As opposed to this, most of the example I see on the web for the strategy pattern only involve either a series of commond paramters or no parameter at all to be passed to the strategy method.

So
1) Am I using the wrong patter to sort this problem?
2) If not how can I pass the Interface (IInstrment) to the client and give a way to the client to change the parameters?

For example


inferface IInstrument
{
double GetPrice()

}


class Stock : Instrument
{

double GetBody();
array[] double earnings{get;set}
double risk;
date today()

}

class Bonds : IInstrument
{
string GetBody();
double rate;

}


Thanks