From the course: Java Design Patterns: Behavioral Part 2
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Challenge: The Visitor pattern - Java Tutorial
From the course: Java Design Patterns: Behavioral Part 2
Challenge: The Visitor pattern
(upbeat music) - [Illustrator] Let's have a look at our final exercise in this course. In this one, you're going to be refactoring an app that's used for adjusting employee salaries using the visitor pattern. So, let's have a quick look at the code. There's an interface called employee, which has a single methods called get salary, which returns an integer. Then there are two concrete implementations called manager and sales person. These both have a salary field where the getter and setter for the salary. Then there is the staff list class, which also implements employee. This contains an array list of employees and in the constructor, a manager and two salespeople are added to this list. And finally, there is the client class, which creates a staff list objects and then prints out a message saying the total salaries paid to all staff. So if I run the app, I can see I get a message on the console saying that…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.