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." Robert C. Martin For example a socket defines a shape of a plug it needs and all devices need to implement this type of a plug to work on electricity. Even … Continue reading Dependency Inversion Principle

Interface Segregation Principle

Interface Segregation Principle states that you should prefer small, cohesive interfaces to fat interfaces. Clients should never be forced to depend on methods they do not need. Example Let's consider a fat IConfigurationSettings interface. It consists of too many elements and should be split into IApplicationIdentitySettings, IPerformanceTuningSettings, IDataAccessSettings and IWebServiceApiSettings. Settings class implements IConfigurationSettings but … Continue reading Interface Segregation Principle

Liskov Substitution Principle

This principle was named after Barbara Liskov who first described the principle in 1988. The Liskov Substitution Principle states that subtypes must be substitutable for their base types. In other words, subtype must be able to replace its base type without altering any of the desirable properties of the base class. Naive OOP teaches use of … Continue reading Liskov Substitution Principle

Open/Closed Principle

The Open/Closed Principle states that modules (classes, methods etc.) should be open for extension but closed for modification. What does it mean? It means that new behavior can be added in the future and no changes to the existing source code will be required. How to change behavior without changing the source code? Rely on abstractions! Example … Continue reading Open/Closed Principle

Single Responsibility Principle

Single responsibility principle states that every class or a module should have only one responsibility. Responsibility means a difference in usage scenario or a reason to change. "There should never be more than one reason for a class to change" Robert C. Martin It is much better to have many small classes with distinct responsibilities … Continue reading Single Responsibility Principle

SOLID principles

SOLID principles are five best programming practices in object oriented design.  These rules help developers build applications that are easy to maintain and extend. Robert C. Martin well known as Uncle Bob identifies four code smells that are indicators of possible deeper problems in code: Rigidity – tendency of a system to be hard to … Continue reading SOLID principles