SOLID principles are like the backbone of OOP, I've gone through with this and obtained a good understanding of this and I thought to share it so that anyone can understand this principle at MAX.
Here is the list of SOLID principles.
|
SRP |
A class should have one, and only one, reason to change. | |
|
OCP |
You should be able to extend a classes behavior, without modifying it. | |
|
LSP |
Derived classes must be substitutable for their base classes. | |
|
ISP |
Make fine grained interfaces that are client specific. | |
|
DIP |
Depend on abstractions, not on concretions. |
Today I am hilighting the Open Closed Principle of SOLID.
Software entities should be open for extension, but closed for modification: Robert Martin
The preceding statement may be a bit confusiing to understand for those who are not very familiar with these principles.
Open for Extension: A class should be open for extension only (for example a derived class or subclasses).
Closed for modification: A class shouldn't be open of modification (for example we should not add code on demand whenever required).
One thing is sure in all software development, most software changes during its life cycle. So, it requires assurance that developers design software that is stable.
For example, let's say you are creating a class to represent an Export. The Export class will export the information/dataset to the desired format like a list of employees and related information to a CSV and text format on behalf of the specified provider. The following sample example is for illustrative purposes only:
public enum ProviderName
{
SQlServer
}
class Export
{
public void ExportFileToDesiredFormat(Provider objProvider)
{
if (objProvider == ProviderName.SQlServer)
{
//Export to CSV,text,.pdf format code segment which depands on provider
return true;
}
return true;
}
}
Now everything looks great. Suppose we come up with one more desired export format. Then at development time it will look like this that is connected with an OLEDB connection:
public enum ProviderName
{
SQlServer,
OLEDB,
Oracle
}
class Export
{
public bool ExportFileToDesiredFormat(string objProvider)
{

Join the conversation! Your thoughts help the community grow.