SOLID Object-Oriented Design

- - posted in 10000 Hours, Flatiron School

SOLID. We want our code to be SOLID. What does this mean?

Sandi Metz’s presentation SOLID Object-Oriented Design outlines the pitfalls of letting software grow without careful attention to design and constant refactoring. The presentation dives into an example of a simple application consisting of a handful of classes. She skillfully shows how it can be streamlined with increased abstraction, thus lessening the chances that future changes will break the code.

I also recently picked-up a copy of Sandi Metz’s Practical Object-Oriented Design in Ruby. The first chapter introduces the principles of SOLID, the foundation of the rest of the book. As a newbie programmer, this seems like a fairly important idea to internalize, so here we go.

In computer programming, SOLID is a mnemonic acronym capturing the ideas of Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion. It was originally introduced by Michael Feathers for the “first five principles” identified by Robert C. Martin in the early 2000s that stands for five basic principles of object-oriented programming and design.

Single Responsibility: A class should have one and only one responsibility.

Open-closed: Software entities should be open for extension, but closed for modification.

Liskov Substitution: Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program. (This particular definition of a subtyping relation, called (strong) behavioral subtyping, was initially introduced by Barbara Liskov, hence the name.)

Interface Segregation: Many client-specific interfaces are better than one general-purpose interface.

Dependency Inversion Principle: Software design should depend upon abstractions, not upon concretions.

SOLID is perhaps the most basic and foundational aspects of successful OO software design and development. The goal of these principles is to create a system that is easy to maintain and extend over time—a critical aspect of successful applications.