2 ms·
Let's say bob wrote One class and Jane wrote another class and these classes are used in many places around the code base. I'm the programmer that has to compo
by leafboi 6y ago
Let's say bob wrote One class and Jane wrote another class and these classes are used in many places around the code base.
I'm the programmer that has to compose these classes... You're telling me that I have to change the implementation/interface of what they wrote? What about the dependencies?
This is what I mean by "Not reusable."
Additionally typical OOP involves mutating state. The purpose of the class is to hold methods that operate on internal state. Otherwise what you're writing is basically function calls under a namespace.
>Seem cleaner than including little addOne functions as global closures.
Again Put it under a namespace called Math; problem solved. The purpose of a namespace is to group functions together. The purpose of a class is to group methods together that operate on shared state.
If your methods don't involve a "this"
function addOne(){
this.value + 1;
}
then you're not really doing OOP. You're just repurposing the class as a namespace.
- wolco 6y agoThe number + 1 or x 1 doesn't require an object or oop. It doesn't require a function either and would be better to just inline. The great thing about repurposing a class as a namespace is I can pass that repurposed namespace package anywhere. You never need to change their code either inject those objects into a new class or extend one and inject the other.
- leafboi 6y ago>The great thing about repurposing a class as a namespace is I can pass that repurposed namespace package anywhere. namespaces can be passed anywhere anyway. >The number + 1 or x 1 doesn't require an object or oop. It doesn't require a function either and would be better to just inline. + 1 and x 1 are just examples. If you take the examples and make it more complex the problem still remains. An inlined expression is still a function. It's just not named. y = function(x){return x+1; b1 = 1 + y(2) x = 2 b2 = 1 + (x + 1) In the above code y(2) and x = 2; x+1; are equivalent. >You never need to change their code either inject those objects into a new class or extend one and inject the other. You rarely ever need to do this in FP, but you need to do this all the time in OOP.