Game Development Reference
In-Depth Information
public void DoWork2()
{
private Worker myWorker = new Worker();
//Send worker to do job 1
myWorker.DoSomething("Manager1", () =>
{
//A piece of very long tedious work
});
//Send worker to do job 2
myWorker.DoSomething("Manager2", () =>
{
//You guessed it, yet more tedious work
});
}
If your delegate also uses a string as a parameter, the preceding example could be used as
a download pattern where a helper library does the entire download and just returns the
XML asset. This asset can then be unpacked and used in the game in your main function.
Compound delegates
Both the configurable method pattern and delegation pattern are very powerful techniques
when used correctly.
Another feature of delegates is that they can be compounded, meaning you can assign
multiple functions to a single delegate. Also, when a delegate is called, all the methods as-
signed to the delegate will run, as shown in the following code. This feature is very handy
when you want to chain several common functions together instead of one:
public class WorkerManager
{
void DoWork()
{
DoJob1();
DoJob2();
DoJob3();
}
Search WWH ::




Custom Search