Implementing SOLID Principles with Dart Code for the Flutter (part 1/6)

Esmaeil Ahmadipour
3 min readMar 28, 2023
S.O.L.I.D Principles

In the world of Object-Oriented Programming (OOP), there are many guidelines, patterns, or design principles. Five of these principles are usually grouped together and known as SOLID. While each of these five principles describes something specific, they overlap, so adopting one of them implies accepting the others.

SOLID principles encourage us to create software that is maintainable, understandable, and more flexible. As a result, as our programs grow larger, we can reduce their complexity and have an easier development experience while also having faster development speed!

When developers work on a program’s design without using SOLID, they can create major problems for future developers working on the project and waste a lot of time, potentially limiting the success of the program under development.

The question is: what happens if we don’t follow SOLID principles?

In short, the answer is that it leads to “Code Rot,” which includes four problems that I will explain in order below.

Rigidity: A small change causes the entire system to be rebuilt.

Fragility: Changes in one module cause unrelated modules to behave incorrectly.

Immobility: The internal components of a module cannot be extracted and reused in new environments. For example, if the login module of an application cannot be used in a completely different system, it is called immobile, which is caused by the connection and dependency between different modules.

Viscosity: Building, testing, and debugging the program takes a long time, especially when even a simple change is costly and requires changes in multiple parts or layers of the code.

The SOLID story dates back to the year 2000 when it was first introduced by Robert C. Martin in his article “Design Principles and Design Patterns.” These concepts were later developed by Michael Feathers, who introduced us to the SOLID acronym. In recent years, these 5 principles have transformed the world of object-oriented programming and changed the way software is written.

Your code always needs refactoring. Your software should be able to accommodate the changing needs of your customers. Therefore, it is always possible to change and improve the written code, whether you are working on the project or the next developer in line. Hence, the importance of SOLID becomes more apparent.

When you use all S.O.L.I.D principles in combination, developing software that is easily manageable becomes much easier for you and other developers.

In the following articles, we will review the implementation details of each section together with Dart codes.

Introduction to SOLID
Single Responsibility Principle
Open Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle