Geeks With Blogs

News This is my new "geekswithblogs" .net blog. I figured it was time to step out just a bit and add another aspect to my current blog located at Agilist Mercenary.
Agilist Mercenary Loosely Coupled Human Code Factory

SOLID came up again in discussion.  What is SOLID?  Well, glad you asked, because I am going to elaborate on the SOLID Principles a bit.

Initial Concept
S Single Responsibility Principle
O Open/Closed Principle
L Liskov Substitution Principle
I Interface Segregation Principle
D Dependency Inversion/Injection Principle

The Single Responsibility Principle (SRP) is stated that every object should have a single responsibility and should be entirely encapsulated by the class.  This helps keep cohesion.  Here is a short example, starting with a basic class.

public class Car
{
    decimal Gas;
    int Doors;
    int Speed;
    decimal RampJumpSpeed;
}

Now I will refactor a little bit to make it a bit more SRP friendly.
public class Car
{
    decimal Gas;
    int Speed;
}
 
public class DuneBuggy : Car
{
    decimal RampJumpSpeed;
}
 
public class EconomyCar : Car
{
    int Doors;
}

What we end up with, instead of one class, is an abstract class and two classes that have their respective methods or properties to keep the responsibilities were they need to be.

The Open Closed Principle (OCP) is one of my favorites, which states simply, that you should be able to extend a classes behavior without modifying it.  There are a couple of ways one can extend a class, by inheritance, composition, or by proxy implementation. 

The Liskov Substitution Principle (LSP) states that a derived class must be substitutable for their base classes.

The Dependency Inversion Principle (DIP) states that one should depend on abstractions and not on concrete implementations.

Finally, the Interface Segregation Principle (ISP) states that fine grain interfaces should be client specific.

So hope that helps with kicking off a basic understanding of SOLID Principles.  I will be following this entry up with some new bits in the near future related to good software design and practice.

Original post.

Posted on Tuesday, April 6, 2010 6:23 PM | Back to top


Comments on this post: SOLID Thoughts

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © GeekAgilistMercenary | Powered by: GeeksWithBlogs.net