S.O.L.I.D

Not just a state of matter

Paul Scarrone

This is a big picture view of design

S

is for

Single Responsibility Principle

Classes should change for only a single reason.

O

is for

Open Closed Principle

Classes should be open for extension, but closed for modification.

WHA?

  • You should design modules that never change.
  • When requirements change, you extend the behavior of such modules by adding new code, not by changing old code that already works.

Open

A module will be said to be open if it is still available for extension. For example, it should be possible to add fields to the data structures it contains, or new elements to the set of functions it performs.

Closed

A module will be said to be closed if it is available for use by other modules. This assumes that the module has been given a well-defined, stable description (the interface in the sense of information hiding).

L

is for

Liskov’s Substitution Principle

Subclasses should be substitutable for their base classes.

Precondition

  • A contract that must be satisfied before a method can be invoked
  • If the precondition is not met, the method should not be invoked

Postcondition

  • Must be true upon method completion
  • if the postcondition is not met, the method should not return

I

is for

Interface Segregation Principle

Many specific interfaces are better than a single, general interface.

Specific Interface

An interface should be responsible for allowing an object to assume a single role, assuming the class of which that object is an instance implements that interface.

D

is for

Dependency Inversion Principle

Depend upon abstractions. Do not depend upon concretions.

WHA?

Use a "factory" to create instances of your classes so they do not have to be coupled on the concrete level

Resources