- S - Single Responsibility Principle
- O - Open/Closed Principle
- L - Liskov’s Substitution Principle
- I - Interface Segregation Principle
- D - Dependency Inversion Principle
“Class should be having one and only one responsibility”. If a class is going to have multiple features (like: download image, save into database, create new image, v..v..). If in the future, the way we download image changes, then we also may have to change to way we safe image into the database. Or if we are going to have a new database, then we have to change also the way we save the image into the new database as well.
-> In this case, better to have a class with one and one responsibility.
"Classes should be open for extension but closed for modification”. If you want to update a class A which was well written by someone else, then instead of modifying it, you must extend its.
"Parent classes should be easily substituted with their child classes without blowing up the application”. If we are using a class which extends from other class. Be sure to follow parent class implementation to avoid misused which may risk the system.
"Many client specific interfaces are better than one general interface”. Instead of having multiple functions inside an interface, try to create multiple interface which is specifed for specific function. For example: Instead of having Interface General with doA() and doB() functions, create 2 interfaces Interface A with doA() and Interface B with doB().
"Classes should depend on abstraction but not on concretion" This is to avoid tight coupling. Class A and Class B does not need to know each other but we use the interface (abstraction) for the communication between them.