Consider a class C and a set of potential feature changes F'. If class C has two responsibilities, it is likely that many F in F' will only affect code for one of those responsibilities in C.
We apply an F to C but, since there are two responsibilities in C it has less closure - it was open to F and to feature changes that applied to the other responsibility.
Now consider separating responsibilities by breaking C into C1 and C2. If F only applies to C1, C2 is closed with respect to F.
Smaller, focused abstractions lead to closure.
Hey Michael,
Thanks, this clarifies the following answer you posted in [1]:
"It’s a funny thing about the design principles. I think that often if you take one, you get many of the others by implication. If you concentrate on SRP, you can end up with OCP without even thinking about it. I think the same is true of OCP.. If you really push it, you will end up with modules with single responsibilities..."
[1] http://web.archive.org/web/20091225221756/http://blog.objectmentor.com/articles/2009/02/26/10-papers-every-programmer-should-read-at-least-twice
Philip
Posted by: Philip_schwarz | July 23, 2013 at 03:04 PM
Ooer, careful, Michael, you're using that word, "Closure," that already has perfectly good credentials elsewhere. Your, "Closure," is neither the mathematical, "Closure," nor anything related to the lambda, "Closure." Just because it's, "Closed for modification," doesn't mean it's an example of a, "Closure." It's an example of, "Being closed."
Posted by: Mulva | July 23, 2013 at 10:15 PM
Hi Michael,
the idea that the SOLID principles are all connected to a common notion (responding to change) has been explored here by Giorgio Sironi:
http://css.dzone.com/articles/solid-principles-are-they
That, in turn, is inspired by Carlo Pescio's work on the physics of software.
Posted by: Vic Ripa | July 23, 2013 at 11:19 PM
I think that is an oversimplification. I'm not sure, whether I'd even agree on the statement that SRP implies OCP.
You could construct a perfectly valid component with exactly one responsibility. Let's call it a dispatcher. If that dispatcher is implemented as cascading if-then-else-statements, then you are required to change that implementation in order to introduce new features.
Via a wrapper you could argue that there is no need for a change in the dispatcher-component. But in that case you'd spread the responsibility for a dispatch on the wrapper and the dispatcher.
But I agree that small and focussed abstractions tend to improve encapsulation.
Posted by: Phillip | July 27, 2013 at 10:27 AM
Howdy! I'm at work surfing around your blog from my new iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the superb work!
Posted by: oral health | September 17, 2013 at 08:12 AM
Thank you for such helpful info
Posted by: devtools korzh | September 20, 2013 at 05:17 AM
This is a topic that's near to my heart... Many thanks! Where are your contact details though?
Posted by: http://www.tapisdeveil.info | November 06, 2013 at 01:46 AM
I hardly drop remarks, however i did a feew searchkng annd wound up here Michael Feathers: The Single Responsibility annd Open/Closed Principle are the Same. And I actually doo have a couple of questions for you if it's allright. Could it be only me or does it look as if like a few of the remarks look as if they are left by brain dead folks? :-P And, if you are posting on additional places, I'd like to keep up with everything freh you have to post. Could you make a list of all of your public pages like your Faacebook page, twitter feed, or linkedin profile?
Posted by: litparapluiepascher.net | November 06, 2013 at 01:56 AM
With havin so much content do yoou ever run into any problems of plagorism or copyright violation? My site has a lot off unique content I've either written myself or outsourced but it looks like a lot of it is popping it up all over the web without my agreement. Do you know any techniques to help stop content from being ripped off? I'd truly appreciate it.
Posted by: www.maxidressesnow.com | November 27, 2013 at 10:46 AM
Hello There. I found your weblog using msn. This is a really well written article. I will be sure to bookmark itt and come back to read more of your helpful info. Thanks for the post. I'll certainly comeback.
Posted by: cocktail dresses | December 03, 2013 at 08:38 PM