Author: admin

Latest Posts
Dependency Inversion Principle: Your Business Logic Should Never Know About Infrastructure

Robert C. Martin’s definition has two parts:
“A. High-level modules should not depend on low-level modules. Both should depend on abstractions.”
“B. Abstractions should not depend on details. Details should depend on abstractions.”
That sounds academic until you see what it actually means.

Interface Segregation Principle: Stop Forcing Clients to Carry Dead Weight

Robert C. Martin’s definition is short: “Clients should not be forced to depend on methods they do not use.”
A client here is any class that implements or depends on an interface. If that class has to implement methods it has no use for, the interface is too wide.

Liskov Substitution Principle: When Inheritance Lies

In 1987, Barbara Liskov stated the following:
“If S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of the program.”
That’s a mouthful. Let’s break it down into plain English.

Open/Closed Principle: Add, Don’t Rewrite

InPost just changed their pricing model. Again. You open ShippingCalculator, find the switch statement, locate the InPost branch, and carefully edit the formula. While you’re in there, you notice the DHL branch looks suspicious too. You touch it. Now two things are broken instead of one.
This is the cost of code that is never finished being modified. The Open/Closed Principle offers a different approach: write code that you add to, not code that you keep rewriting.

1 2