Implementing the visitor pattern