Today, I encountered the visitor pattern in the SLD implementation inside Geotools. This is reason enough to consider this pattern in the world of Ruby. Especially because I read recently this post where visitor is supposed to be more an antipattern that a pattern. This is because Ruby supports extension of objects at runtime. Nevertheless, I need to check it out!
A simple implementation of a Visitor is accomplished in 3 steps:
Recently I read here that there are GOF patterns which cannot be applied for every language (in Ruby, metaprogramming takes place so that some patterns are unnecessary). But I’m sure that factories are still sexy, no matter what programming language is used. That’s simply an intelligent way to create objects in one place instead of scatter “new Type()” everywhere in your code. That’s true for Ruby as well.
Java Geeks know howto implement Singletons in Java. There are few rules to be considered:
- define private constructor
- add a static method (getInstance) which has full control about the creation of the single object
- add the final modifier to the class to avoid defining subclasses