SoC and SOLID in Practice
After a few months the order calculation is no longer a toy. Marketing regularly changes discounts, logistics adds carriers, finance requires a single rounding. Now the separation of responsibilities rests on facts, not a hunch - and the boundaries can be drawn confidently.
function calculateOrder(order, customer, deliveryPolicy) {
const subtotal = calculateSubtotal(order.items);
const discount = calculateDiscount(subtotal, customer);
const delivery = deliveryPolicy.calculate({
subtotal,
address: order.address,
});
return roundMoney(subtotal - discount + delivery);
}We're not obliged to turn every part into a class or microservice - modules with explicit functions are enough to start. This keeps the simplicity and at the same time draws useful boundaries. Where SOLID is here: the calculation function is responsible only for the order of computation; the discount policy changes separately; delivery gets a small deliveryPolicy contract, not the whole application object; a concrete carrier can be replaced without rewriting the calculation. Where SOLID would be excessive: create an interface and factory for every arithmetic operation and you get more code but no more independent changes - that's already architecture for architecture's sake.
Which part changes for which reason, and which boundary fits it, is convenient to keep in a table.
Part · Reason to change · Fitting boundary
- Discount - Marketing policy; A separate pure function or module
- Delivery - Carrier, region, and tariff; A small deliveryPolicy contract
- Rounding - A single financial rule; One shared roundMoney source
- Order scenario - The order of business operations; An orchestration function without integration details
Boundaries come from experience, not from a template. The same separations, imposed from day one, would be premature architecture. Here they're justified because the parts already have different owners and different rates of change.
All six principles revealed themselves on one function. What remains is to assemble them into a single order of decision.