Flashcard: SOLID design principle

Currently, I am refreshing and improving my knowledge of data structures, algorithms, and design techniques. Thus, I’ve decided to introduce a new post category on my website, namely, flashcards. Here, I will these topics in the form of questions and answers.

This post will cover the SOLID design principle.

What is the purpose of the SOLID design principle?

  • The SOLID principle aims to foster more maintainable and easier to understand designs.
  • The SOLID principle aims to foster codebases that are easier to modify.
  • The SOLID principle aims to reduce the risk of issues introduction.

Which principle represents the “S” in the SOLID, what does that principle say, and which goal does it have?

  • The “S” stands for the Single responsibility principle.
  • The Single responsibility principle instructs that a class should have only one responsibility.
  • The goal of the principle is to simplify classes.

Which principle represents the “O” in the SOLID, what does that principle say, and which goal does it have?

  • The “O” stands for the Open/closed principle.
  • The Open/closed principle guides to design classes that are open for modification. In other words, the software engineer must design classes with Change in mind. On the other hand, the interface of a class must be closed for modification.
  • The goal of the principle is to design classes that are easy to change or extend without breaking the application.

Which principle represents the “L” in the SOLID, what does that principle say, and which goal does it have?

  • The “L” stands for the Liskov substitution principle.
  • The principle instructs to design classes in a way so they could be substituted at runtime. For instance, if a class inherits from a base class, then it can be referenced as an instance of that base class. This means that subclasses must behave exactly as their superclasses do.
  • The goal is to have clear hierarchies.

Which principle represents the “I” in the SOLID, what does that principle say, and which goal does it have?

  • The “I” stands for the Interface segregation principle.
  • The principle instructs that interfaces must contain only methods that have a single responsibility.
  • The goal is to reduce the number of dependencies and keep systems decoupled.

Which principle represents the “D” in the SOLID, what does that principle say, and which goal does it have?

  • The “D” stands for the Dependency inversion principle.
  • The principle says that modules should not depend on details but abstractions.
  • The goal is to protect classes from changes to specific classes they depend on.
%d