O'Reilly logo

C# 3.0 Design Patterns by Judith Bishop

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Behavioral Patterns: Visitor, Interpreter, and Memento

In this chapter, we'll consider the final three core design patterns. The Visitor and Interpreter patterns are well-known in compiler-writing circles. However, they also apply wherever operations are defined on structures according to specific rules, and the operations and structures are defined separately. The Memento pattern rounds out the behavioral group by showing how the state of objects can be saved and restored.

Visitor Pattern

Role

The Visitor pattern defines and performs new operations on all the elements of an existing structure, without altering its classes.

Illustration

This illustration takes us into the realms of student record systems. These days, it's typical for courses to be assessed in several ways, which all add up to a final result. At the start of a course, instructors are required to declare the components that will contribute to the assessment. The students' marks are recorded throughout the semester and then totaled up at the end according to the weights that were specified. For example, consider the extract from a spreadsheet containing the marks for a course on Programming Languages in Figure 10-1. We can deduce that the assessment for the course consisted of:

  • Five laboratories (or labs) (2 percent each)

  • A midterm evaluation consisting of a laboratory component (10 percent) and a theory component (15 percent)

  • An assignment that is a take-home laboratory (10 percent)

  • An examination consisting of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required