Here is how to build a chain of responsibility is a standard manner:
var command1 = new Command1(); var command2 = new Command2("Test"); command1.NextInChain = command2; command1.Execute(null);Here is the same construct in a fluent manner:
var chain = new ChainBuilder<ChainCommand>() .Add<Command1>() .Add<Command2>(() => new Command2("Test")) .Build(); chain.Execute(null);Which one do you like the most? In my case I prefer the fluent way. Building a chain of responsibility in not that difficult if you have only a handful of element to chain, but if you have more it become boring to remember to link the previous element to the next. My builder take car of that for you. Because of “fluent” concept you always now what comes next. For exmaple the ChainBuilder class only expose some overload of Add and a Build method.
So if you like this way of thinking, join my codeplex project and give me your feedback about it.
See : http://fluentpatterns.codeplex.com/