I mean design smell like temporal coupling. Void method has no type safe strict description in its signature about cases why and when it should be called. So it's only up to documentation. And using it is based on faith in correctness of side effects.
So should we try get rid of void methods in interfaces?
Void methods are not design smells.
Object-orientation (unlike functional programming) allows side-effects, for example changing the internals of the object the method is called on. This is normal.
Whether that is good or not is another question. Functional programming is certainly more powerful in terms of expressiveness. It is possible to write code that is almost impossible to misuse (when it compiles it works).
Also, void methods don't cause temporal coupling in general. Temporal coupling would mean, that there must be another method that must be called before or after the method, otherwise the method call does not make sense.
Of course you have to know the semantics of the method call, in other words what it means. That is to be expected, and would be the same in functional programming also, for functions with the same signature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With