SOLID/

directory
v0.0.0-...-50f873e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2023 License: GPL-3.0

README

Introduction:

  • Design patterns are typically for object oriented based languages.
  • In golang we don't have Inheritance and week encapsulation, so golang is not fully object oriented.

Solid Design Principles:

  • SOLID is an acronym for five sets of principles that was first coined by "Robert C Martin"
  • The Five principles of object oriented designs are:
    • SIP - Single Responsibility Principle
    • OCP - Open-Closed Principle
    • LSP - Liskov Substitution Principle
    • ISP - Interface Segregation Principle
    • DIP - Dependency Injection Principle

Single Responsible Principle:

A class(type: struct) should have one, and only one reason to change.

  • Ignoring the above rules, will lead to GOD Object
  • Module should be highly cohesive and loosely coupled.

Open Closed Principle:

Entities should be open for extension, but closed for modification.

  • Code doesn't have to be changed every time when the requirements change.
  • In golang, code should be able to override a struct, using Stratergy Design Pattern

Liskov Substitution Principle:

LSP states that objects of a superclass should be replaceable with objects of its subclasses without breaking the application.

  • eg: API which works correctly in base class, when extended by the derived class, it should work correctly in the derived class.
  • LSP deals with Inheritance, which is primarily not applicable in golang, but we can apply LSP in go, using interface and polymorphism.

Interface Segregation Principle:

Clients should not be forced to depend upon interfaces that they do not use.

  • The goal is to reduce the side effects and frequency of required changes by splitting the software into multiple, independent parts.
  • The above statement is achievable if we define our interface for a specific task.

Dependency Inversion Principle:

High-level modules should not depend on low-level modules; both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.

  • Its about inverting the classic dependency between high-level and low-level components by abstracting away the interaction between them.
  • The general concept is to reduce the coupling between the classes/struct.

Directories

Path Synopsis
DIP
ISP
LSP
OCP
SRP

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL