This technique (it's name is
fluent interfaces) can save some space and provide more clarity if applied carefully. Carefully as in, not suddenly invoking a method that returns another object, so the last two lines would apply to an IBar whereas the first few lines configure an IFoo object ;)
But it can turn a difficult configuration into a breeze. For example, in my unit tests NMock allows me to write:
| Expect.Once.On(mockedObject).Method("BeginSomething").WithAnyParameters(); |
| Expect.Once.On(mockedObject).Method("EndSomething").WithAnyParameters().Throw( |
| new MockException("Intentional failure for unit testing") |
| ); |
| |
| Foo(mockedObject); |
| |
| mockery.VerifyAllExpectationsHaveBeenMet(); |
Imagine what a mess that would make if I wanted to tell NMock through some traditional interfaces and methods how to behave and what to look for.
Check out my
website and
blog for some interesting articles and useful utility classes!
Nuclex Framework:
threaded particles,
skinnable GUI,
vector fonts,
texture atlasses and lots more.
WiX XNA Installer: Professional-looking MSI installer template for XNA games.