CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Dave Laribee

"Whoso would be a man must be a nonconformist." - Ralph Waldo Emerson

Why SOLID? GIMME AN S!

There was some chatter on twitter today about why SOLID principles are a good idea. When designing object systems we often tote around a lot of acronyms for principles of good design, but why are these things principles? It's not enough to simply say "just because." So right here and now I'd like to examine the "why" of some time tested OO aphorisms.

Yes, SOLID has been covered many times in many places, but it's hard to find a single resource explaining the reasoning behind these ideas. Please spare me the "I wrote this post 18 months ago." I won't go into the "what" or "how" because I think that's been covered inside and out. We're here to talk about the principals behind the principals. Namely: what does SOLID buy you.

Now that all necessary disclaimers have been, well, disclaimed, here goes!

Single Responsibility Principle (SRP)

SRP simply states that a class should have one and only one reason to change. There is a clear reason for this: making sure your classes embody one purpose in life makes your system more receptive to change, more stable. Once you've nailed an object's raison d'être chances are you can move on with your life. You don't need to introduce changes that can, in turn, introduce instability. From Uncle Bob Martin:

If a class has more then one responsibility, then the responsibilities become coupled. Changes to one responsibility may impair or inhibit the class’ ability to meet the others. This kind of coupling leads to fragile designs that break in unexpected ways when changed.

Changes can also ripple through the system as classes depending on our multi-responsibility class (which is more likely to change than a single responsibility class)

have clients in other programs. It's worth considering your responsibilities and favoring more discrete classes with fewer methods.

SRP is really about analyzing cohesion. If you're interested in going deeper, I recommend checking out this entry on cohesion to better understand the science behind SRP. Did you, for example, know their are different levels and forms of cohesion?

Next up: the Open-Closed Principle...


Published Sep 09 2008, 04:10 PM by Dave Laribee
Filed under: , ,

Comments

Derick Bailey said:

i actually did talk about why solid, recently... am doing presentations for the teams in my company on how solid helps us achieve high cohesion, low coupling, good encapsulation.

my "summary" slide and info is here:

www.derickbailey.com/.../ObjectOrientedDevelopmentViaTheSOLIDSoftwareDevelopmentPrinciples.aspx

# September 9, 2008 4:21 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# September 9, 2008 4:26 PM

Dave Laribee said:

Nice angle for the presentation. Weird that no one has unpacked the why on their blog. Of course I don't read the everything, so... nothing new under the sun. But then you know that old managemen axiomt: repetition is key.

It's true.

# September 9, 2008 4:27 PM

Colin Jack said:

Good post, in my view the best way to pick up these principles is to buy the book and then try/discuss them:

www.amazon.co.uk/.../ref=sr_1_2

# September 9, 2008 4:28 PM

PandaWoos said:

Thorough annoyed by french words in an english blog but otherwise very interesting

# September 9, 2008 7:18 PM

Dew Drop - September 10, 2008 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - September 10, 2008 | Alvin Ashcraft's Morning Dew

# September 10, 2008 9:10 AM

Dave Laribee said:

The next leg of our quest to uncover the deeper driving forces behind SOLID principles brings us to the

# September 11, 2008 1:04 AM

Mirrored Blogs said:

The next leg of our quest to uncover the deeper driving forces behind SOLID principles brings us to the

# September 11, 2008 2:09 AM

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas said:

Pingback from  Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas

# September 11, 2008 5:12 AM

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas said:

Pingback from  Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas

# September 13, 2008 8:55 PM

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas said:

Pingback from  Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas

# September 15, 2008 9:04 AM

Community Blogs said:

The next leg of our quest to uncover the deeper driving forces behind SOLID principles brings us to the

# September 15, 2008 2:19 PM

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas said:

Pingback from  Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas

# September 16, 2008 9:09 AM

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas said:

Pingback from  Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas

# September 21, 2008 9:28 PM

Dave Laribee said:

.csharp { font-family: 'Consolas', 'Courier New'; color: #33F;} Thus far in my journey

# September 22, 2008 12:04 PM

Community Blogs said:

.csharp { font-family: 'Consolas', 'Courier New'; color: #33F;} Thus far in my journey

# September 22, 2008 12:33 PM

Mirrored Blogs said:

.csharp { font-family: 'Consolas', 'Courier New'; color: #33F;} Thus far in my journey

# September 22, 2008 12:42 PM

Why SOLID? GIMME AN L! - taccato! trend tracker, cool hunting, new business ideas said:

Pingback from  Why SOLID? GIMME AN L! - taccato! trend tracker, cool hunting, new business ideas

# October 6, 2008 5:05 PM

Kevin Pang said:

10 Programming Proverbs Every Developer Should Know

# October 7, 2008 12:17 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors

Proudly Partnered With