Reputation: 1436
How do I name this "WorkDistribtor"? This looks like a pattern but I cant's say what it is.
interface IWorker
{
void Do();
}
class WorkerOne: IWorker
{
public void Do() {...}
}
class WorkerTwo: IWorker
{
public void Do() {...}
}
// ...
Instead of using one specific worker to Do() the job I am introducing an indirection that decides which actual worker should do the job. This indirection implements the same interface as a Worker but doesn't actually do the work but delegating it.
class WorkDistributor: IWorker
{
private _workerOne = new WorkerOne();
private _workerTwo = new WorkerTwo();
//...
//delegate work to the different workers
//depending on some conditions
public void Do()
{
if (whateverCondition)
{
_workerOne.Do();
}
if (anotherCondition)
{
_workerTwo.Do();
}
}
}
Upvotes: 1
Views: 86
Reputation: 6900
It looks most likely like the Strategy
pattern (also known as the policy pattern):
http://en.wikipedia.org/wiki/Strategy_pattern
where you actually allow each specific implementation to define different behavior depending on the context, and algorithms can be selected at runtime using your selector class(the one that defines the actual context).
Upvotes: 1