3 ms·
...I agree with your comments on Liskov Substitution Principle, that the fact it's even possible is a weakness in OOP type systems. But the rest of your exampl
by james_s_tayler 7y ago
...I agree with your comments on Liskov Substitution Principle, that the fact it's even possible is a weakness in OOP type systems.
But the rest of your examples are very far off base.
I somewhat agree with Single Responsibility being perhaps not quite right as "single" isn't always desired, appropriate or possible. But the general philosophy is absolutely on point. It's an instruction to carefully consider whether a component should be responsible for something or not and if not then think about where else that responsibility should lie. It gets pretty gnarly when you see things that just have way too many responsibilities. They become unwieldy. An object being responsible for holding and manipulating its state isn't what I would class as a responsibility. That is below the line. That's thinking far too granularly about what a responsibility is.
Same for open/closed. There is a great picture that represents open/closed of a human body (being the closed system) that you can put different layers of clothes on (open for extension) which I think beautifully captures the essence of the principle. When this is done right it's an absolute blessing. You mostly find it in frameworks that have a life-cycle and at certain points (say before anything happens or after everything has happened) they provide an overridable method with no behavior. That method allows you to insert logic the framework designers didn't think to cater for, but also keeps the framework life-cycle intact.
The example of dependency inversion just doesn't make sense. If you're creating a string manipulation library it should take strings and nothing else. It doesn't need anything else. If you're creating a string manipulation library in the first place you probably should just use the standard library. Maybe that's just a bad example, but I still don't agree with your sentiment with always avoid runtime dependency injection.
Forgetting the string manipulation example - I'm curious what you have in mind when you say "modules should instead communicate with one another". How does this communication take place? What language are we talking about and what does some code look like? Mostly what comes to mind when I think of that are either newing up an instance of a class or calling a static method, or perhaps making some kind of http/tcp request?
- crimsonalucard 7y agoFor the first two principles... in OOP they are just guidelines operating at the layer of business logic. There are programming languages/styles that implement these "principles" as laws all the way down to primitive components. For DI: https://news.ycombinator.com/item?id=19910450 https://news.ycombinator.com/item?id=19910450 See what I wrote about composition. I also have an example about a Car and engine class later in the thread. Function Composition > Dependency Injection. > ...I agree with your comments on Liskov Substitution Principle, that the fact it's even possible is a weakness in OOP type systems. It's not actually a weakness in the type system. It's the weakness in the language. The language should never allow for such types to be constructed. Basically Inheritance is not compatible with the type checker. You get rid of inheritance, you get rid of this problem.