4 ms·
- One quality measure of an abstraction is the complexity ofits interface (ie API size). - Another measure is the amount of state the abstraction enca
by Confusion 17y ago
- One quality measure of an abstraction is the complexity
ofits interface (ie API size).
- Another measure is the amount of state the abstraction
encapsulates.
The simplest abstraction of many interfaces is two methods:
setParameterForNextCall(paramName, paramValue)
call(functionName)
The API is small, not complex and the amount of state is small, given that parameters are only set right before a call, all parameters are cleared after every call and no other state is retained. Yet it's clear to anyone that this isn't a good abstraction and that it doesn't result in an implementation that requires few unit tests. It requires an immense amount of documentation and allows a great many variations that yield bad/unexpected results.
Hence, good abstractions require few unit tests.
Abstractions don't have unit tests: implementations have unit tests. It's the size and complexity of the implementation made possible by the abstraction that matters.
- ekiru 17y agoThat interface is certainly inconvenient to use, and potentially quite dangerous without a clearParameters(). It's not at all a rebuttal of the article, though. The article points out that the number of unit tests a design requires is larger for more complicated designs. An interface like yours would require no fewer tests than another interface exposing the same functionality using conventional function calls.