COMP2511 Week 10

Agenda

  • Admin Stuff
  • Visitor Pattern
  • Kahoot

Admin Stuff

  • Final lab to get all your labs marked off
  • Assignment 2 interviews during the lab
    • Contribution distribution
    • Explain one subtask each from Task 1 and Task 2
    • Demo dungeon generation
  • If 85% of the cohort fills out myExperience, every single student in the course will receive 1 bonus course mark.

Visitor Pattern

Motivation

 

How can I add functionalities to legacy systems without violating the open/closed principle?

 

 

Visitor Pattern

What is it?

Behavioural design pattern that allow algorithms and objects that the algorithms operate on to be separated
 

Benefits

  • OCP: introduce behaviour to classes without changing their implementation.
  • SRP: functionality and data in an object can be separated


When to use?

New operations need to be added to all elements of an existing object structure

 

UML Diagram

  • Element classes must have an accept function that invokes the visit function of the Visitor
  • New behaviour is added in the visit function of the Visitor

Double Dispatch

Exercise

Kahoot

COMP2511 Tutorial 10

By Matthew Liu

COMP2511 Tutorial 10

  • 97