- The Open-Closed Principle (OCP): Classes should be open for extension, and closed for modification.
- The Don’t Repeat Yourself Principle (DRY): Avoid duplicate code by abstracting out things that are common and placing those things in a single location.
- The Single Responsibility Principle (SRP): Every object in your system should have a single responsibility, and all the objects services should be focused carrying out that single responsibility.
- The Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types. (The LSP is all about well-designed inheritance.)
- The Hollywood Principle: Don’t call us, we’ll call you.
- The Law of Demeter (The principle of least knowledge): Only talk to your immediate friends.
- Delegation: is when you hand over the responsibility for a particular task to another class or method.
- Composition: allows you to use behavior from a family of other classes, and to change that behavior at runtime.
- Aggregation: is when one class is used as part of another class, but still exists outside of that other class.
Encapsulate what varies.
Favor composition over inheritance.
Program to interfaces, not implementations.
Strive for loosely coupled designs between objects that interact.
Depend on abstractions. Do not depend on concrete classes.
Head First Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&D (Head First)by Brett D. McLaughlin, Gary Pollice, Dave West Read more about this title…