CodeSOD: And I Try, and I Try |
If you want to put everything under test, you have to write code like this.
At least, thats what Alexs co-worker said to him, when Alex demanded an explanation for this block of code.
public interface ITrier
{
void Try(
Action tryAction,
Func catchFunc)
where TException : Exception;
void Try(
Action tryAction,
Func catchFunc,
Action finallyAction)
where TException : Exception;
TReturn Try(
Func tryFunc,
Func catchFunc)
where TException : Exception;
TReturn Try(
Func tryFunc,
Func catchFunc,
Action finallyAction)
where TException : Exception;
TReturn Try(
Func tryFunc,
Func catchFunc,
Action finallyAction,
Func defaultReturnFunc)
where TException : Exception;
TReturn Try(
Func tryFunc,
Func catchFunc,
Func defaultReturnFunc)
where TException : Exception;
}
Now, this code doesnt precisely do anything, but dont worry- Alexs co-worker built an AbstractTrier class, which implements this interface, and can be inherited from in any situation where your testing patterns prohibit the use of try/catch blocks. Theres also a MockTrier, making this useful for testing, somehow.
And before you point out that theres a perfectly good language construct that could be used instead of this interface or its implementors, Alex warns us that the genius behind this code also has crafted ILooper, and IConditional.
[Advertisement] BuildMaster is more than just an automation tool: it brings together the people, process, and practices that allow teams to deliver software rapidly, reliably, and responsibly. And it's incredibly easy to get started; download now and use the built-in tutorials and wizards to get your builds and/or deploys automated!
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |