Skip to content

Instantly share code, notes, and snippets.

@dandvl
Last active December 30, 2020 19:29
Show Gist options
  • Save dandvl/d23a56f09ae04e3608e254999f311748 to your computer and use it in GitHub Desktop.
Save dandvl/d23a56f09ae04e3608e254999f311748 to your computer and use it in GitHub Desktop.

Single Responsibility Principle (SRP)

A Class shouldn't have more than one Responsibility
Violation - when the POJO class saves into the database and generates reports)

Open Closed Principle (OCP)

Open for extension, Closed for modification. Every time we add sibling classes, we shouldn't modify the existing methods that are working with them.
Violation - switch statements in the methods to call different behaviors for each sibling class, instead of using polymorphism

Liskov Substitution Principle (LSP)

Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program. Violation - when you pass a subclass to a method and obtain a different result when you pass the class

Interface Segregation Principle (ISP)

Many client-specific interfaces are better than one general-purpose interface
Violation - when you implement an interface and leave implementation empty for some methods)

Dependency Inversion Principle (DIP)

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.
Violation - when the classes relies directly on other classes instead of interfaces)

Medium article Uncle's Bob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment