Posts

Showing posts from August, 2024

01. What is SOLID?

Image
01. What is SOLID? What is SOLID? SOLID  is a set of   five design principles  in object-oriented programming that make your code cleaner, modular, flexible, and maintainable S – Single Responsibility Principle (SRP) O – Open/Closed Principle (OCP) L – Liskov Substitution Principle (LSP) I – Interface Segregation Principle (ISP) D – Dependency Inversion Principle (DIP) 1. Single Responsibility Principle (SRP)  A class, ethos or veritable should responsible to handle only one thing (have only one reason to change). Bad: class Report { void generateReport () {} void saveToFile () {} } Good: class ReportGenerator { void generate () {} } class ReportSaver { void saveToFile () {} } 2. Open/Closed Principle (OCP) Software entities should be open for extension but closed for modification .  Bad: class Payment { void process (String type) { if (type.equals( "credit" )) {} else if (type.equals( "paypal" )) {} } } Good: interface PaymentMethod { ...