SOLID principles: The Definitive Guide (Part I)

Moises Gamio
Javarevisited
Published in
3 min readNov 22, 2021

--

SOLID principles tell you how to arrange your functions into classes and how those classes should be interrelated.

Robert C. Martin introduced it. Design Principles.

When SOLID principles are applied correctly, your software infrastructure will tolerate changes, be easier to understand and focus on reusable components.

Let's start with the first principle.

SOLID principle: Single Responsibility Principle (SRP)

… “a class should only have one reason to change“

This principle states that a class should only have one responsibility.

For instance, imagine an online store that issues its cards for its customers, and from the beginning, the Payment and Card teams are in mutual agreement to apply for interest and lock cards from customers who are in late payments for 14 days or more.

In the following code, we have the first design of the Payment Class, which supports both requirements.

The Problem: The Class has more than one responsibility

--

--

Moises Gamio
Javarevisited

Do you like coding? I want to make what is complex been easy to understand by learning the fundamentals of computer science and software design.