SOLID is a default, not a religion.
Most articles teach the five principles with toy examples — a Square that violates LSP, a Logger that violates SRP. You finish having memorised five acronyms with no idea what to do on Monday morning when your real order service has 11 reasons to change and a switch statement on payment type.
So I took a real, ugly 60-line order-processing service that breaks every SOLID rule, and refactored it one principle at a time.
The starting point
public class OrderService { public void PlaceOrder ( Order order ) { // validate, apply discount, charge Stripe, // open SqlConnection, send SMTP email, // append to a log file // 60 lines. 6 jobs. 3 hard-coded providers. } }
Enter fullscreen mode
Exit fullscreen mode
Untestable without a real Stripe key, a real database, and an SMTP server.…