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.
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |