I've always had the feeling that many of the common design patterns were simply recipes for doing something that your programming language does not do for you. The standard Gang of Four design patterns apply to many different programming languages, because these are things that most object oriented programming languages, at least at the time, weren't prepared to help you with. Just which design patterns are relevant is something that changes over time, as languages evolve to do more for you. A classic example is the singleton pattern and Scala. Scala provides singleton objects as a language feature, and most of the implementation concerns addressed by the singleton pattern are now handled by the language.
On the other hand, as languages get more powerful, we expect more from them, and are naturally inclined to attempt to do more sophisticated things than we used to. I often get myself in trouble with Scala, because I try to do things I would never attempt to do in Java. In a position like this, we may need to consider new patterns to get around the newly discovered limitations of the new language. I "invented" a little Scala-specific pattern that I will show here, that I've used to help me overcome a small problem I come across from time to time.
Showing posts with label type parameters. Show all posts
Showing posts with label type parameters. Show all posts
2015-01-08
2011-07-01
Scala Enums: Real Life Example
I wanted to follow up my previous post on Scala Enums with a real-life example. The beauty of this example is my ability to use advanced typing techniques such as type parameters, mixin traits, even a composite pattern, in what basically amounts to a simple enumeration type. This code is quite easy to read, and perfectly conveys my intentions. I don't even want to imagine what I would have done in Java for something like this.
Subscribe to:
Posts (Atom)