Create Minimal and Complete interfaces
Minimal and Complete has been one of my guiding principles in my work for almost 20 years. It has helped me write better interfaces and classes as well as architect components and systems.
Scott Meyers introduced the concept of minimal and complete in Effective C++.
A minimal interface is as small as possible without losing required functionality.
Minimal interfaces don’t have multiple methods that do the same thing; callers shouldn’t need to make a coin-toss decision between methods.
A complete interface isn’t missing anything. It fully satisfies its single responsibility.
Just coding all the methods isn’t enough. The interface defines a complete contract including behavior, validation, and performance requirements.
- Write out the code you expect most callers to use. Put yourself in the caller’s shoes.
- Minimal and complete can quickly become difficult when convenience methods are added. Consider if the convenient methods are really needed, or if the inconvenient methods can be made easier to call.
- Be aware of false need. Sometimes knowing the constraints of the implementation will cause developers to violate minimal and complete.