Lecture 19 continuted: More Visitors
Ambient temperature: 74.4oF
Concepts
- Dr. Wong demonstrates the visitor design pattern:
- The HostA-HostB-HostC visitor pattern from last class’ lecture.
- Linked Lists with counting, summation, copying, and mapped addition.
- The visitor pattern is an example of “double dispatch:” First the visitor object is dispatched to a host object, then a particular method is dispatched from the host to the visitor object.
- Accumulators: Unfortunately, still forming a succinct summary; got distracted by loop invariants :(
Quotes
- “What is a duck? A duck is a thing that acts like a duck.” – Dr. Wong
- “Ducktyping is about ‘can we use it as a duck?’ What I’m talking about is ‘how do we define a duck?'” – Dr. Wong
Resources
- Lecture 19 webpage on visitors: http://www.clear.rice.edu/comp310/f12/lectures/lec19
- Simple visitor demo: http://www.clear.rice.edu/comp310/f12/demos/VisitorDemo/
- Linked list visitor demo: http://www.clear.rice.edu/comp310/f12/demos/ListFW/
- Double dispatch on Wikipedia: http://en.wikipedia.org/wiki/Double_dispatch