Re:A polyglot's guide to multiple dispatch
by Someone on Tuesday April 19, 2016 @01:09PM
(#11528429)
1) I do not see how that's multiple dispatch. In C++ parlance, it requires C to be virtual, but that's it.
2) For symmetry, I would make C abstract in the parent class, and create two subclasses, one implementing C, one implementing C'.
3) Having done that, the logic defining the order of the steps can be moved into the parent class.
4) If you want to mock things, it may help to make A, B, and D overridable in the parent class, too.
This is single dispatch.
Re:A polyglot's guide to multiple dispatch
by jcoffland on Tuesday April 19, 2016 @01:03PM
(#11528380)
This looks like simple polymorphism to me. A.k.a., single dispatch.
Re:A polyglot's guide to multiple dispatch
by pasquinelli on Tuesday April 19, 2016 @01:09PM
(#11528426)
i don't understand what this has to do with multiple dispatch. only the this argument is dynamically dispatched on. multiple dispatch is the same idea, except with more than just the this argument being dispatched on, allowing you to define custom methods for any combination of possible arguments and getting to the right one at runtime.
Re:A polyglot's guide to multiple dispatch
by shaunparker on Tuesday April 19, 2016 @01:03PM
(#11528376)
Isn't this single dispatch?
The naive implementation would be:
You should implement it as: process() becomes a lot easier to test, since you only need to mock out/outsmart figure_out_right_process() instead of mimicking the right logic for [conditions for process 2]. You can test each process independently, since you don't need to fulfil the [conditions for process 2] in each test, and if those conditions should change, you only need to change figure_out_right_process() instead of at each branch in your code.It may look verbose with only one branch, but the second you have more than two processes, or nested branches, the class based way looks a lot cleaner.