This problem expresses the duality dilemma between procedural/functional and OO approaches. In the former, it is easy to add a new function, but hard to extend with new data (for all existing functions); The latter, is easy to add new data, but difficult to extend with a new function (to all existing ADTs). To be more rigorous, the last sentence is not entirely correct (inheritance, polymorphism and dynamic binding makes all the difference). If one can add the new function (feature) in the topmost parent class, and its implementation works for descendant classes, it is a simple and easy solution. Nevertheless, it requires opening the parent class, and there are indeed many cases where the sentence is essentially correct.
External dispatch solution:
(Source code) (Compiled Eiffel code)
