For most of the 90’s and the beginning of the aughts, I was the CTO of a small training and consulting company. When I went to work there, our primary platform was Clipper, which was a rapid-application tool for building DOS applications atop dBASE files. Clipper was object-based, and could be made fully object-oriented with an extension library. We had an advantage over our competitors because we built an extensive object-oriented framework for cranking out applications. We were happy as clams: we had both a thriving training and consulting business.
In this part two of the series we’ll learn how to use traits to implement the decorator pattern. Decorator is a popular “GOF Pattern” that’s implemented well in the JDK IO API. Scala traits remove quite a bit of ceremony from the implementation of this pattern. In addition to the benefits of traits we saw in part 1 of this series, in this part we’ll see the advantages of applying multiple traits both at the class and instance level.
Domain Specific Languages (DSLs) are often littered with the accidental complexity of the host language. Have you ever seen a supposedly "friendly" language expression like "ride(minutes(10)).on(bus).towards(Basel)"? The newest version of Groovy contains a language feature that aims to eliminate the noise of all those extra periods and parenthesis so that your DSL looks more like "ride 10.minutes on bus towards Basel". This article shows you, step-by-step, how to use Groovy Command Expressions and plain old metaprogramming to write just this DSL, and also offers advice on when, and when not, to use this new language feature.