![]() ![]() SRP, if well understood, is a fine concept. Conclusion: SRP isn't "bad", but it took a clear concept, and made it confusing. So it deters a programmer from including functionality that is unlikely to change. Usually leaves out the "likely to change" clause. Essentially it means that each class and module in a program should focus on a single task. So what exactly is the single responsibility principle The term is pretty self descriptive. Plus, the SRP, as commonly expressed, e.g. While the concept of single responsibility has been around for a while it was popularized in 2003 by Uncle Bob. A general opinion of the Stack Overflow veterans is that SRP is horribly misunderstood. Only respond to the "Single" part the principle. ![]() It is clear from newbie questions on Stack Overflow that the "Responsibility" part is seldom understood (can't blame them) and most budding programmers After much struggle, he finally got it right in "Gather together the things that change for the same reasons.", though he should add a "likely". Which has needed continuous elaboration by Dr. In contrast, the term "responsibility" is less clear, and "Single Responsibility Principle" is overly simplistic, frequently misunderstood, and begs the question of "what is a responsibility", A programmer should understand what is a "design decision". The principle that a module should encapsulate a single design decision that is likely to change is understandable, pragmatic, and realistic. Separate those things that change for different reasons." Did SRP improve upon the work of Dr. "Gather together the things that change for the same reasons. Of people representing a single narrowly defined business function." When changes are requested, those changes can only originateįrom a single person, or rather, a single tightly coupled group "When you write a software module, you want to make sure that He argues that the "responsibility" is this: "who must the design of the program respond to?". Originally (2003) Uncle Bob expressed this as "A class should have only one reason to change." Which begs the question, "what is a reason to change"? In this followup A "module" should encapsulate only one such decision (or possibly zero), separating it from other difficult decisions. You should abstract / encapsulate the difficult decisions, especially those that are likely to change.įor example, if you are using some hot new startup's miracle Cloud Database, that is likely to change in a few years, and should be abstracted. To hide such a decision from the others." Or design decisions which are likely to change. "We propose instead that one begins with a list of difficult design decisions This was inspired by early (1972) work of David L. In this post, let's consider the "S", the Single Responsibility Principle. I believe that many of them are misunderstood, misapplied, overrated, and all too often they much less important than other software engineering principles. "Uncle Bob", are amongst the most cited by programmers. SOLID principles, developed by Robert Martin a.k.a. ![]()
0 Comments
Leave a Reply. |