<p>An <a href="https://stackoverflow.com/questions/15241/does-anyone-have-any-real-world-experience-of-csla#15357">answer</a> to a Stack Overflow question stated that a particular framework violated a plain and simple OOP rule: Single Responsibility Principle (SRP).</p>

<p><strong>Is the Single Responsibility Principle <em>really</em> a rule of OOP?</strong></p>

<p>My understanding of the definition of Object Orientated Programming is "a paradigm where objects and their behaviour are used to create software". This includes the following techniques: Encapsulation, Polymorphism &amp; Inheritance.</p>

<p>Now don't get me wrong - I believe SRP to be the key to most good OO designs, but I feel there are cases where this principle can and should be broken (just like database normalization rules). I aggressively push the benefits of SRP, and the great majority of my code follows this principle. </p>

<p><em>But, is it a rule, and thus implies that it shouldn't be broken?</em></p>

[{'answer_id': 15432, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 6, 'selected': True, 'text': "<p>Very few rules, if any, in software development are without exception. Some people think there are no place for <em>goto</em> but they're wrong. </p>\n\n<p>As far as OOP goes, there isn't a single definition of object-orientedness so depending on who you ask you'll get a different set of hard and soft principles, patterns, and practices.</p>\n\n<p>The classic idea of OOP is that messages are sent to otherwise opaque objects and the objects interpret the message with knowledge of their own innards and then perform a function of some sort.</p>\n\n<p>SRP is a software engineering principle that can apply to the role of a class, or a function, or a module. It contributes to the cohesion of something so that it behaves well put together without unrelated bits hanging off of it or having multiple roles that intertwine and complicate things.</p>\n\n<p>Even with just one responsibilty, that can still range from a single function to a group of loosely related functions that are part of a common theme. As long as you're avoiding jury-rigging an element to take the responsibilty of something it wasn't primarily designed for or doing some other ad-hoc thing that dilute the simplicity of an object, then violate whatever principle you want.</p>\n\n<p>But I find that it's easier to get SRP correct then to do something more elaborate that is just as robust.</p>\n"}, {'answer_id': 15482, 'author': 'bruceatk', 'author_id': 791, 'author_profile': 'https://Stackoverflow.com/users/791', 'pm_score': 3, 'selected': False, 'text': '<p>None of these rules are laws.  They are more guidelines and best practices.  There are times when it doesn\'t make sense to follow "the rules" and you need to do what is best for your situation.   </p>\n\n<p>Don\'t be afraid to do what you think is right.  You might actually come up with newer and better rules.</p>\n'}, {'answer_id': 15517, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 1, 'selected': False, 'text': '<p>Ahh, I guess this pertains to an answer I gave. :)</p>\n\n<p>As with most rules and laws, there are underlying motives by which these rules are relevant -- if the underlying motive is not present or applicable to your case, then you are free to bend/break the rules according to your own needs.</p>\n\n<p>That being said, SRP is not a rule of OOP per se, but are considered best practices to create OOP applications that are both easily extensible and unit-testable.</p>\n\n<p>Both are characteristics that I consider as of utmost importance in enterprise application development, where maintenance of existing applications occupies more time than new development does.</p>\n'}, {'answer_id': 45391, 'author': 'Tim Williscroft', 'author_id': 2789, 'author_profile': 'https://Stackoverflow.com/users/2789', 'pm_score': 3, 'selected': False, 'text': '<p>To quote Captain Barbossa:</p>\n\n<p>"..And secondly, you must be a pirate for the pirate\'s code to apply and you\'re not. \nAnd thirdly, the code is more what you\'d call "guidelines" than actual rules...."</p>\n\n<p>To quote Jack Sparrow  &amp; Gibbs.\n"I thought you were supposed to keep to the code."\nMr. Gibbs: "We figured they were more actual guidelines. "</p>\n\n<p>So clearly Pirates understand this pretty well.</p>\n\n<p>The "rules" could be understood via the patterns movement as "Forces"</p>\n\n<p>So there is a force trying to make the class have a single responsibility. (cohesion)</p>\n\n<p>But there is also a force trying to keep the coupling to other classes down.</p>\n\n<p>As with all design ( not just code) the answer is that it depends.</p>\n'}, {'answer_id': 316830, 'author': 'Joris Timmermans', 'author_id': 33987, 'author_profile': 'https://Stackoverflow.com/users/33987', 'pm_score': 0, 'selected': False, 'text': '<p>As many of the other posters have said, all rules are made to be broken.<br>\nThat being said, I do think that SRP is one of the more important rules for writing good code.  It\'s not specific to Object Oriented programming, but the "encapsulation" part of OOP is very hard to do right if the class does not have a single responsibility.</p>\n\n<p>After all, how do you correctly and simply encapsulate a class with multiple responsibilities?  Usually the answer is multiple interfaces and in many languages that can help quite a bit, but it\'s still confusing to the users of your class that it may apply in completely different ways in different situations.</p>\n'}, {'answer_id': 317586, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': -1, 'selected': False, 'text': '<p>SRP is just another expression of ISP :-) . </p>\n\n<p>And the "P" means "principle" , not "rule" :D </p>\n'}]
['https://Stackoverflow.com/questions/15412', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/708/']