I recently had the pleasure of reading an article written by one of my Systematic colleagues, Jan Reher, entitled "Policy-Based Design in the Real World" published in the C++ Users Journal. The article shows an example from a real application of the use of policy-based design, as described in Alexandrescu's book Modern C++ Design.
Policy-based design allows functionality to be parametrized in a number of independent dimensions. The textbook solution is an elegant application of C++ templates and multiple inheritance. The point of Jan's article was to demonstrate that the textbook solution can actually be used in a real application.
I found the article very interesting for a number of reasons. One of Jan's concerns was the real-world utility of policy-based design. I see this as a broader issue: many of us are familiar with the situation where an elegant textbook solution evolves into an unmanageable mess when applied in practice, so it is always good to get real validation of such a solution. On a practical note, since I have worked mainly with Java for the last few years, it was interesting to try to recast Jan's solution in Java (pre J2SE 5.0's generics). What became rapidly apparent was that the solution would be significantly more clunky in Java. Actually, even with generics, the Java solution would be less concise than the C++ one due to the use of multiple inheritance in the C++ solution.
No comments:
Post a Comment