Design Principles

Here are some of the basic design principles that one should keep in mind while developing applications.


The Open Closed Principle (OCP)
A module should be open for extension but closed for modification
We should write our modules so that they can be extended, without requiring them to be modified. In other
words, we want to be able to change what the modules do, without changing the source code of the modules

The Liskov Substitution Principle (LSP) 
Subclasses should be substitutable for their base classes
That is, a user of a base class should continue to function properly if a derivative of that base class is passed to it
Restating the LSP, we can say that, in order to be substitutable, the contract of the base class must be honored by the derived class
Restating the LSP once again, this time in terms of the contracts, a derived class is
substitutable for its base class if:
1. Its pre-conditions are no stronger than the base class method.
2. Its post-conditions are no weaker than the base class method. Or, in other words, derived methods should expect no more and provide no less

The Dependency Inversion Principle (DIP)
Depend upon Abstractions. Do not depend upon concretions

Depending upon Abstractions.
Every dependency in the design should target an interface, or an abstract class.
No dependency should target a concrete class

The Interface Segregation Principle
Many client specific interfaces are better than one general purpose interface
If you have a class that has several clients, rather than loading the class with all the methods that the clients need, create specific interfaces for each client and multiply inherit them into the class

Comments