Dave Laribee

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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...


Posted 09-09-2008 4:10 PM by Dave Laribee
Filed under: , ,

[Advertisement]

Comments

Derick Bailey wrote re: Why SOLID? GIMME AN S!
on 09-09-2008 4:21 PM

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

DotNetKicks.com wrote Why SOLID? Gimme an
on 09-09-2008 4:26 PM

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

Dave Laribee wrote re: Why SOLID? GIMME AN S!
on 09-09-2008 4:27 PM

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.

Colin Jack wrote re: Why SOLID? GIMME AN S!
on 09-09-2008 4:28 PM

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

PandaWoos wrote re: Why SOLID? GIMME AN S!
on 09-09-2008 7:18 PM

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

Dew Drop - September 10, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - September 10, 2008 | Alvin Ashcraft's Morning Dew
on 09-10-2008 9:10 AM

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

Dave Laribee wrote Why SOLID - GIMME AN O!
on 09-11-2008 1:04 AM

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

Mirrored Blogs wrote Why SOLID? GIMME AN O!
on 09-11-2008 2:09 AM

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

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas wrote Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas
on 09-11-2008 5:12 AM

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

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas wrote Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas
on 09-13-2008 8:55 PM

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

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas wrote Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas
on 09-15-2008 9:04 AM

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

Community Blogs wrote Why SOLID? GIMME AN O!
on 09-15-2008 2:19 PM

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

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas wrote Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas
on 09-16-2008 9:09 AM

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

Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas wrote Why SOLID? GIMME AN O! - taccato! trend tracker, cool hunting, new business ideas
on 09-21-2008 9:28 PM

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

Dave Laribee wrote Why SOLID? GIMME AN L!
on 09-22-2008 12:04 PM

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

Community Blogs wrote Why SOLID? GIMME AN L!
on 09-22-2008 12:33 PM

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

Mirrored Blogs wrote Why SOLID? GIMME AN L!
on 09-22-2008 12:42 PM

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

Why SOLID? GIMME AN L! - taccato! trend tracker, cool hunting, new business ideas wrote Why SOLID? GIMME AN L! - taccato! trend tracker, cool hunting, new business ideas
on 10-06-2008 5:05 PM

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

Kevin Pang wrote 10 Programming Proverbs Every Developer Should Know
on 10-07-2008 12:17 PM

10 Programming Proverbs Every Developer Should Know

Add a Comment

(required)  
(optional)
(required)  
Remember Me?