2 ms·
Any trivial example demonstrating how something like this works will seem obfuscatory, because examples are usually trivially solved with other approaches. But
by barrkel 15y ago
Any trivial example demonstrating how something like this works will seem obfuscatory, because examples are usually trivially solved with other approaches. But see the Expression Problem[1] for the deep problem.
Whether it's an appropriate solution depends on whether introducing new operations or new data types is more common; and where the modularity boundaries are. For example, what if the base class in the hierarchy doesn't have a method for the task you want to perform, and you can't add one because it belongs to third party code, and nor can you implement it appropriately for every descendant?
[1] http://en.wikipedia.org/wiki/Expression_problem http://en.wikipedia.org/wiki/Expression_problem