Saturday, November 13, 2010

..........Strategy Pattern

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

///
/// Entry point into console application.
///

static void Main()
{
CEmployee objCEmployee

objCEmployee = new CManager();
objCEmployee.DefineWork();

objCEmployee = new CDeveloper();
objCEmployee.DefineWork();
}

///
/// The 'Strategy' abstract class
///

abstract class CEmployee
{
public abstract void DefineWork();
}

///
/// A 'ConcreteStrategy' class
///

class CManager : CEmployee
{
public override void DefineWork()
{
Console.WriteLine("This is Manager Works.");
}
}

///
/// A 'ConcreteStrategy' class
///

class CDeveloper : CEmployee
{
public override void DefineWork()
{
Console.WriteLine( "This is Developer Work.");
}
}

No comments:

Followers

Link