lec 35: behavioural design patterns, part 5

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:10 PM on 4/13/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

15 Terms

1
New cards

What is the Visitor pattern?

A pattern that lets you define new operations on an object structure without changing the element classes.

2
New cards

What problem does Visitor solve in the slides?

We want to add new reports for employee objects without putting reporting logic inside the employee classes.

3
New cards

Why would putting report code into Employee classes be bad?

It would violate Single Responsibility Principle and make later changes harder.

4
New cards

What is the definition of Visitor?

Represent an operation to be performed on the elements of an object structure; it lets you define a new operation without changing the element classes.

5
New cards

When is Visitor especially useful?

When element classes rarely change, but new operations need to be added often.

6
New cards

What is the abstract element in the slides’ example?

Employee.

7
New cards

What are the concrete elements in the example?

HourlyEmployee and SalariedEmployee.

8
New cards

What is the abstract visitor in the example?

EmployeeVisitor.

9
New cards

What are the concrete visitors in the example?

HourlyPayReport and AllPayReport.

10
New cards

What method do elements implement in Visitor?

accept(visitor).

11
New cards

What does accept() usually do?

It calls visitor->visit(this).

12
New cards

What methods does EmployeeVisitor define?

visit(HourlyEmployee) and visit(SalariedEmployee).

13
New cards

Why not just call visit() directly on an Employee*?

Because visit() needs the concrete subclass type, not just the abstract parent type.

14
New cards

What is one advantage of Visitor?

Adding new operations is easy.

15
New cards

What is one disadvantage of Visitor?

Adding new concrete element classes is hard.