3 ms·
There is no need to modify existing implementations when extending an interface using multiple dispatch. You would need to add the required implementations, bu
by codr7 6y ago
There is no need to modify existing implementations when extending an interface using multiple dispatch.
You would need to add the required implementations, but there's really no way around that since the logic has to go somewhere.
And as soon as you start actually dispatching on multiple arguments, using sum types to solve the same prolem quickly turns into spaghetti.
- tsimionescu 6y ago> There is no need to modify existing implementations when extending an interface using multiple dispatch. Sure there is. If I have a function that takes a Foo and a Bar, and it calls a generic method on them, the generic method must have methods that cover the real subtypes of Foo and Bar. If someone had created subtypes of Foo and Bar and defined methods on all the generic methods that they knew about, and now you create a new generic method, you have absolutely broken the interface just as much as adding a new method to Iterable in Java.
- codr7 6y agoIt must have enough methods to get the behavior you want, that doesn't always mean all subtypes. Assuming you're running a version of Java that supports default implementations, which may often be used to avoid breaking the interface. Sum types are a different story, as you would have to dive into existing code.