Skip to main content

SOLID

Single Responsibility, Open–Closed, Liskov Substitution, Interface Segregation, Dependency Inversion

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/solid

In short

SOLID is a set of five object-oriented design principles that help developers write code that is easier to understand, extend, test, and maintain.

What are the SOLID principles?

SOLID is an acronym for five guidelines for designing classes and modules, popularized by software engineer Robert C. Martin in the early 2000s. Each letter stands for one principle, and together they aim to keep code flexible, so new features can be added without breaking existing ones. They are most often discussed in object-oriented programming, but the ideas apply to many kinds of code.

S is the Single Responsibility Principle: a class should have only one reason to change. O is the Open–Closed Principle: code should be open for extension but closed for modification, meaning you add new behavior by writing new code rather than editing working code. L is the Liskov Substitution Principle: a subclass should work anywhere its parent class is expected.

I is the Interface Segregation Principle: several small, focused interfaces are better than one large interface that forces classes to implement methods they don't need. D is the Dependency Inversion Principle: high-level code should depend on abstractions, such as interfaces, rather than on concrete details like a specific database class.

An analogy is a well-organized toolbox: each tool does one job, new tools can be added without modifying the old ones, and any screwdriver of the right size fits the same screw. SOLID principles are guidelines, not strict laws; applying them too rigidly can produce many tiny classes and unnecessary layers of abstraction.

Key takeaways

  • S: Single Responsibility, one reason to change.
  • O: Open–Closed, extend behavior without editing existing code.
  • L: Liskov Substitution, subclasses must be safely interchangeable with their parents.
  • I: Interface Segregation, prefer small, focused interfaces.
  • D: Dependency Inversion, depend on abstractions, not concrete classes.

Example

Dependency Inversion in TypeScripttypescript
// Depend on an interface, not on a concrete class
interface Notifier {
  send(message: string): void;
}

class EmailNotifier implements Notifier {
  send(message: string) { console.log("Email:", message); }
}

class OrderService {
  constructor(private notifier: Notifier) {} // any Notifier works here
  placeOrder() { this.notifier.send("Order placed"); }
}

new OrderService(new EmailNotifier()).placeOrder();

Readers ask

What does SOLID stand for?

SOLID stands for the Single Responsibility, Open–Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles.

What is the Single Responsibility Principle?

The Single Responsibility Principle says a class or module should have only one reason to change, meaning it is responsible for one part of the system's behavior. For example, a class that both calculates invoices and sends emails should usually be split in two.

Do SOLID principles apply outside object-oriented programming?

Yes. The ideas behind them, such as small focused units and depending on abstractions, are useful in functional and modular code too, even though the wording comes from object-oriented design.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings