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.
Challenge: The Visitor pattern - Java Tutorial
From the course: Complete Guide to Java Design Patterns: Creational, Behavioral, and Structural
Challenge: The Visitor pattern
In this final challenge, you'll be implementing the visitor pattern in a ticketing system app. So firstly, there's an interface called TicketElement, which has a single method called getPrice. Then there are two implementations of this. So the first one is the AdultTicket class. And in here the price is initially set to 10. Then in the getPrice method, we return that price field, and there's also a setPrice method to change the price. The other class that implements TicketElement is the GroupTicket class. So in this one there's a single field called elements which is an array list of other ticket elements. Then in the getPrice method, it actually gets all of the prices of the tickets in the list and adds them together. Then there's a method called addElement to add a ticket elements to the list and getElements which returns the list. Finally, there's the App class, which has a main method. So in here we're creating a group ticket and then two adult tickets which we're then adding to…
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)