Main menu

Pages

Solid Principles In brief

What are the SOLID Principles

They are guidelines for building software in standard form and allow your software to scale easily and be maintained well 

The owner of those principles is Robert C. Martin

Today we are gonna talk about them individually by images to illustrate and explain it in brie

SOLID Consists of 5 characters each one referring to the index of each principle

  • S = Single Responsibility Principle

  • O = Open/Closed Principle

  • L = Liskov Substitution Principle

  • I = Interface Segregation Principle

  • D = Dependency Inversion Principle

Single Responsibility Principle :

    - Class must have a single role or responsibility if the class has many it leads to miss leading and provide a lot of bugs.

    - We need to separate responsibility to produce clean and maintained code

   - Each software module should have one and only one reason to change




Open/Closed Principle:

    - Open for extension closed for modification

    - If we have a class already written and we need to modify it  this will affect all the references using this class

    - All you can do with existed class is to add inside it for example property or functions 





Liskov Substitution Principle:

    Subtypes must be substitutable for their base type.

    - If we have 2 classes X, Y and Y inherit from X, Y must behave like a parent (x) and not change its parent behavior

    - We need to enforce consistency so parent and child can be used easily 



 Interface Segregation Principle:

    - Clients should not be forced to depend on methods they do not use

    - If we have a class inherited from the interface class should depend on methods that will use



Dependency Inversion Principle:

    - High-level modules should not depend on low-level modules. Both should depend on the abstraction.

    - High-level modules: the class that has a function will execute an action using a tool

    - low-level modules: the tool that the class will use to execute an action 

    - Abstraction: interface which will connect the two classes 

    - We need to reduce the dependency of high-level classes on the low-level class

    - Abstraction must not depend on details and must detail depend on abstraction


References:

Comments