Codele / Advanced programming
SOLID: five rules for clean design
Five habits keep big programs easy to change. Pick one, watch a messy design hurt, then watch the tidy version fix it.
- SOLID is five design habits: Single responsibility, Open/closed, Liskov substitution, Interface segregation, Dependency inversion. They are habits, not laws: they help most when a program grows.
- Single responsibility: a class has one job, so it has one reason to change. Open/closed: add new things by adding new classes, not by editing old, working code.
- Liskov substitution: a child must keep every promise of its parent. If a Penguin cannot do what a Bird promises, the promise was wrong. Interface segregation: many small promises, not one giant one.
- Dependency inversion: big, important code depends on a promise (an interface), not on a small detail. Python and JavaScript have no interface keyword, so the promise is the set of methods the code calls. Go has no inheritance: its interfaces do this job.
Loading the playable lesson…