From the course: Complete Guide to Java Design Patterns: Creational, Behavioral, and Structural
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Understand the Visitor pattern - Java Tutorial
From the course: Complete Guide to Java Design Patterns: Creational, Behavioral, and Structural
Understand the Visitor pattern
Imagine you have a tree structure of objects, and you want to perform an operation on all the elements of it. The visitor pattern allows you to do this without making changes to the elements themselves. Instead, you have a separate visitor objects, which is passed to each object to perform the operation. As a real-world analogy, imagine someone drives a car to a mechanic. The mechanic temporarily takes over the car to fix some things, and then the car is driven away again. The mechanics might do different kinds of fixes depending on the problem, and there also might be different kinds of vehicles, such as trucks and buses and so on. The different fixes might be similar for each different type of vehicle, but also slightly different. Let's see what the visitor pattern looks like in a Java program. So let's say you have an interface with some concrete implementations of it. And let's say you want to apply some operation to each of the concrete implementations. The operation will be…
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
(Locked)
Understand abstract factories3m 7s
-
(Locked)
Recognize where to use abstract factories3m 53s
-
(Locked)
Create factories for families of objects6m 4s
-
(Locked)
Implement the complete Abstract Factory pattern6m 1s
-
(Locked)
Challenge: The Abstract Factory pattern1m 36s
-
(Locked)
Solution: The Abstract Factory pattern2m 34s
-
(Locked)
-
-
(Locked)
Understand the Chain of Responsibility pattern1m 23s
-
(Locked)
Recognize where to use the Chain of Responsibility pattern2m 35s
-
(Locked)
Implement a successor chain4m 49s
-
(Locked)
Challenge: The Chain of Responsibility pattern1m 48s
-
(Locked)
Solution: The Chain of Responsibility pattern3m 59s
-
(Locked)