Skip navigation

This page is a work in progress… a compilation of information about object-oriented design principles and values.

S.O.L.I.D. Class Design Principles

Collected by Robert C. Martin for his book “Applying Principles and Patterns”

Single Responsibility Principle (SRP)

A class should have only one reason to change. For example, if a change to the business rules causes a class to change, then a change to the database schema, GUI, report format, or any other segment of the system should not force that class to change.

Open/Closed Principle (OCP)

Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.

Liskov substitution principle (LSP)

Subtypes must be substitutable for their base types. If class A inherits from class B, then wherever you can use A you should be able to use B. E.g. remember that square is not necessarily a rectangle! When extending: Preconditions cannot be straightened, Postconditions cannot be loosened, visible Invariants cannot be changed (?). Invariants: users depend on this both before and after sending a message. Use a proper set-based inheritance relationship. Not following set semantics is very risky. Subsumption Rule: A reference to a subtype can be used in any context where a reference to a super type is expected. This principle extremely limits what SHOULD be done with the pure extension (inheritance) mechanism. Do not follow at your own risk.

Interface Segregation Principle (ISP)

The dependency of one class to another one should depend on the smallest possible interface.

Dependency Inversion Principle (DIP)

Depend upon abstractions (interfaces), not upon concrete classes.

Other Important Ones

Law of Demeter

aka Principle of Least Knowledge: Only talk to your friends

Any method M of an object O may only invoke the methods of the following kinds of objects:

  • itself
  • its arguments/parameters
  • any objects it creates/instantiates
  • its direct component objects


Hollywood Principle

Don’t call us, we’ll call you.

Don’t Repeat Yourself (DRY)

Remove duplication.

Program to an interface, not an implementation

Maybe just another way to say dependency inversion.

You Ain’t Gonna Need It (YAGNI)

Do not add code that you “think will be used later”. Add code only at “Last Responsible Moment”

Keep It Simple, Stupid (KISS)

What is the simplest thing that could possibly work?

And More

Encapsulation and Information Hiding

Separation of Concerns (SoC)

High Cohesion

Low/Loose coupling

Convention over Configuration (CoC)

Command-query separation (CQS)

[edit] Design by Contract (DbC)

Dependency Injection (DI)

Inversion of Control (IoC)

Avoid Fragile Baseclass

Has-a Is-a

What is Identity


Option-operand separation

Intention Revealing Names

Zero Friction Development

Encapsulate Variation

Separate what varies from what stays the same. Also known as Serenity Principle.

Composition over inheritance

  • Head First Design patterns page 23, 243, 397

Common Closure Principle

Classes that change together must be placed in the same package.


    • subra
    • Posted August 20, 2008 at 9:09 pm
    • Permalink

    Excellent collection and am happy to see all of this one place

    • Kenny Grant
    • Posted December 2, 2008 at 5:29 pm
    • Permalink

    Most comprehensive list I’ve seen, great work. Hollywood principle made me laugh..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: