Being SOLID in Dart.

1. SRP — Single Responsibility principle

The class should only change for a single reason.

A Generic User Class with all responsibility packed in a single class.
User class
Validators and UserAuth.

2. OCP — Open Closed Principle

Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification.

Adding a new shape.

3. LSP — Liskov’s Substitution Principle

This principle stands for the statement that a child class should be able to replace/substitute its parent class.

Rectangle squr = Square(8, 5);print(squr.calculateArea()); -- OUTPUT  = 64     [ Expected OUTPUT -- 40 ]
Applying Liskov’s substitution principle

4. ISP — Interface Segregation Principle

Don’t impose methods on clients if they are of no use, simple and straight If something is useless for me I should not be forced to keep it.

Forcing unnecessary methods.
Implementing ISP

5. DIP — Dependency Inversion Principle

  • High-level modules/classes should not depend on low-level modules/classes. Both should depend upon abstractions.
  • Abstractions should not depend upon details. Details should depend upon abstractions.
DIP implementation



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store