Friday, February 18, 2011

What is SOLID

I was reading a few posts about OOP and I wanted to write about what is SOLID and why is so important. Lets start by the formal definition:

SOLID stands for:

S - Single responsibility principle (SRP):
The notion that an object should have only a single responsibility. You know how hard it can be to find the source of a bug/issue. If you encapsulate and abstract the functionality of your object, reducing its responsibilities to a single one, it would be a lot easier to find out if the problem is being generated by that object. The reason it is important to keep a class focused on a single concern is that it makes the class more robust. Look out for the separation of concerns concept, that´s a big deal in software development and software architecture.

O - Open/closed principle (OCP)
The notion that “software entities … should be open for extension, but closed for modification”. OOP basic principles. Inheritance, polymorphism and abstraction. Any good developer should understand and apply this principle.

L - Liskov substitution principle (LSP)
the notion that “objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”. See also design by contract. Put your interfaces to work dude, make sure you work with contracts, so you can modify, extend or replace implementations without breaking the whole thing !

I - Interface segregation principle (ISP)
The notion that “many client specific interfaces are better than one general purpose interface.” Again, we are trying to encapsulate and abstract functionality. The days of "one big file" are far behind, you should divide and conquer always, and not try to just throw everything in a single place.

D - Dependency inversion principle (DIP)
The notion that one should “Depend upon Abstractions. Do not depend upon concretions.”
Dependency injection is one method of following this principle. Dependency inversion is a very useful concept to understand, although I think is not that easy to master. This has become more important with frameworks and standard libraries and is about reversing the control in a program´s life cycle. Dependency Injections is related to the concept and is one of the methods to achieve it. Check out Enterprise Library and the Unity Application Block for .NET specifics and keep reading and revising general software development articles and documentation about DI. Its worth it.

Cheers!
-arbbot

No comments:

Post a Comment