5 ms·
If you learn only 1 thing from SOLID, it would be the Single Responsibility Principle (SRP). Honestly, this is over 80% of the value of SOLID. The Interface Se
by SideburnsOfDoom 12y ago
If you learn only 1 thing from SOLID, it would be the Single Responsibility Principle (SRP). Honestly, this is over 80% of the value of SOLID.
The Interface Segregation Principle is a special case of SRP, and Open-Closed Principle and Liskov Substitution Principle are most applicable to deep inheritance hierarchies, which are rarer than they were. SRP pushes you towards "composition over inheritance" which is also good.
Yes, using a lot of interfaces and an IoC container does push you towards a particular style, but it's not that hard to read once you know it.
- moomin 12y agoISP is underrated. I think the problem is that the logical endpoint of ISP is that every interface has one method, which is unworkable in a classic OO language. At this point you realize that what you really want is functions as parameters and move on with your life. :) Not true if there are laws specifying the relationship between the methods. But way more often true than you'd expect from reading a (good) java codebase.
- SideburnsOfDoom 12y agoThe ISP is good, but you can derive it from SRP: The SRP says that things should have one responsibility, and the ISP says that Interfaces are things too. I saw some Java 8 recently. The automatic conversion from a lambda to an interface with one (compatible) method was interesting, but yeah, it points to the problem that what you sometimes really want is just a function.
- adwn 12y ago> it points to the problem that what you sometimes really want is just a function Interestingly, this fact has been known to procedural as well as functional programming proponents for decades (one of the few aspects on which they agree).
- platz 12y agoThe problem with SRP is it's hard to define what that "one reason" is exactly. http://sklivvz.com/posts/i-dont-love-the-single-responsibility-principle http://sklivvz.com/posts/i-dont-love-the-single-responsibili... > sometimes really want is just a function summed up nicely here: http://blog.ploeh.dk/2014/03/10/solid-the-next-step-is-functional/ http://blog.ploeh.dk/2014/03/10/solid-the-next-step-is-funct...
- regularfry 12y agoI find Uncle Bob's definition of SRP makes far more sense if you change it from "responsibility for something" to "responsibility to someone." That is, there should be one and only one person, or business role, who would want a given class to change. The "one reason" then becomes "That guy over there gave me a business justification for it," and nothing else really matters. It's just as easily read then as "a class cannot serve two masters."
- tel 12y agoThat matches well with the original guiding principles for software modularity: modules should encapsulate deferred or changing decisions, nothing more or less.
- platz 12y agoI think the point is you cannot predict what decisions are going to change or be deferred. That's why I like the interpretations of this that try to make change in any direction more reasonable. Otherwise you get people building things like abstract factories "just in case".
- tel 12y agoI think that's a little silly, or rather worded imprecisely. Freedom in all directions prohibits all structure, all implementation.
- 12y ago
- dragonwriter 12y ago> Liskov Substitution Principle are most applicable to deep inheritance hierarchies, which are rarer than they were. The Liskov Substitution Principle is applicable wherever inheritance is used, and failing to follow it anywhere when using inheritance pretty much guarantees bugs will eventually emerge. If its "most applicable to deep inheritance hierarchies", its because the cost of finding and fixing the source of the bugs resulting from violating the LSP is greatest in such hierarchies.
- tel 12y agoThis is key! Most people try to at least ad hoc'edly treat "inherits from" as "is subtype of". Many typed languages even encode this directly. This is a total lie unless LSP is followed, however. LSP doesn't do much more than actually define what the necessary and sufficient properties of the "is subtype of" are.