A minimal interface is a stratified-design pattern that keeps important business concepts accessible through a small, powerful set of operations. Other operations should be built from those primitives, directly or indirectly, rather than added to lower layers whenever a new feature appears. section 8.4 section 9.12
When a new function can be implemented above an existing layer, prefer that placement. This keeps lower layers focused, protects implementation details, and avoids expanding the interface that other code and teams must understand and maintain. section 9.11 section 9.12
A shopping-cart campaign
A watch discount applies when a cart exceeds $100 and contains a watch. The low-level version loops through the cart and inspects its map representation. The higher-level version combines existing operations such as calculating the total and checking whether an item is present. The second version expresses the business rule more directly without enlarging the abstraction barrier. section 9.11
Use the pattern as a design check:
- Ask whether the new function belongs to the purpose of the lower layer or merely uses that layer. section 9.11
- Prefer existing operations when they can express the feature clearly. section 9.12
- Aim for a complete, minimal, durable interface, while treating that form as an ideal rather than a final destination. section 9.12
function getsWatchDiscount(cart) {
var total = calcTotal(cart);
var hasWatch = isInCart("watch");
return total > 100 && hasWatch;
}
Compare the business-level discount rule with its compact implementation using existing cart operations. section 9.11
