2 ms·
What? Class methods are responsible for upholding the class invariants. That is, it provides you a way to encapsulate internal state. Of course all your class m
by kaba0 6y ago
What? Class methods are responsible for upholding the class invariants. That is, it provides you a way to encapsulate internal state. Of course all your class methods should be responsible for upholding that - but if you find that there are too many methods, you perhaps need a rethinking of architecture.
Perhaps adding a wrapper class over an inner class? The inner class is the only thing responsible for upholding said class invariants, but the outer one can access it in different ways, without hurting the invariants.
- blackrock 6y agoThe problem is that it is a giant internal state. And your class can be thousands of lines long. Of which you have to keep open, as you develop it. Which forces you to keep the entire code base in your head, thus increasing the cognitive load on developing the classes. Of course, there may be ways to refactor it, but the tools given in most OOP languages, tends to be insufficient.
- kaba0 6y agoIt’s as big of an internal state as you make it/minimum as large as the problem domain requires. Functional programming doesn’t solve any of these problems by itself. There are cases where mutating state is better, and there are others, where it is worse fit. And the latter can just as well be expressed inside a class, like there is no requirement for mutation. I think the two should go hand-in-hand, and for different parts of a program different paradigms can be used? Maybe even add actos-based programming as a possibility, but there is nothing inherently bad with OOP imo, and it is the best way to encapsulate some logic.