
What
is the need for Strategy Pattern
|
class contextClass
{
private strategyClass stratObj;
public contextClass(strategyClass obj) {
stratObj = obj;
}
public void setContext() {
stratObj.triggerAlgorithm();
}
}
abstract class strategyClass {
public abstract void triggerAlgorithm();
}
The strategyClass
can now be inherited by different classes and the context class can trigger
any of these derived classes by using the following statements:
contextClass conObj = new contextClass(new derivedClass1());
conObj.setContext();
_______________________________________________________________________
FREE Subscription
Subscribe
to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.
Note
: We never rent, trade, or sell my email lists to
anyone.
We assure that your privacy is respected
and protected.
Visit .NET Programming Tutorial Homepage
______________________________________________________