Consider the classical problem of devising a solution for handling shapes in a 2D space. For example: squares and circles. An object oriented solution starts by looking at the (abstract) data, enriching their interface with proper useful exported features (perimeter, area, position, move, draw, etc.) and their semantics. For instance: CIRCLE, SQUARE, and, of course, the deferred parent class SHAPE.
Consider now the problem of shape interaction, for instance, the distance between two shapes. (This is a typical example of a binary method.)
Clearly, to fetch the proper distance feature, a single dispatch approach will not be enough. We need a dynamic binding mechanism applicable to multiple dispatch objects (two).
The proposed external dispatch mechanism provides a modular, object-oriented solution.
Note 1: The excellent abstraction and modularity properties of OOP are at our disposal in this approach. An intersect boolean function is fully implemented in the TWO_SHAPES class and is applicable to all existing and future SHAPES.
Note 2: Class SHAPE and its descendants know nothing on the existence of TWO_SHAPES (and descendants).
External dispatch solution:
(Source code) (Compiled Eiffel code)
