Visitor Design Pattern

Derek Banas · 288K views · 2012 · 13:31

Open on YouTube

Software architecture & designSoftware practice, open source & careerstutorial

Why Stack Overflow recommends it

Stack Overflow users link it as a worked, step-by-step example of implementing the Visitor pattern, including return types and method overloading across visitable classes.

Recommended by 1 people across 1 different months, 2015 to 2017.

What it is

A 13-minute tutorial by Derek Banas on the Visitor design pattern, the last video in his design pattern series. It shows how to add new operations to classes of different types without heavily modifying them, using Java code.

What people said

Recommends David Velasquez · 2017-01 · Stack Overflow · on “Correct way to cast a list of objects from a parent class to various child classes”

This was exactly what I was looking for! It works perfectly. Thank you. For anyone reading this, a really good Youtube tutorial on how to implement this pattern is found here [this video] .

Cites Run · 2015-01 · Stack Overflow · on “interface: php vs java”

I notice something very different between java and php on interface, when you create the same methods in their interfaces. PHP: interface Visitor { public function visit(Visitable $Visitable); public function visit(Visitable2 $Visitable2); // this is wrong in php. } Java: interface Visitor { public double visit(Visitable Visitable); public double visit(Visitable2 Visitable2); // this is ok in java } you can look at the check it out on this video [this video] at 3:35 for java. how come java allows that? what does double do anything? and no double in php?

Cites Alex Dn · 2015-04 · Stack Overflow · on “Visitor Design Pattern - return type”

I used the Visitor design pattern to solve one of the issues within our system. As a reference how to implement it I used DoFactory site [LINK] and This YouTube video [this video] . In DoFactory example, the Visitor uses a method with return type of "void" and in YouTube video, author uses "double". Why I ask: After presenting the solution to company CTO, he accepted to call it Visitor, but he claims like if Visitor is not "void" as stated in GoF [LINK] , than it like abuse the real Visitor pattern. Question: Is it required for Visitor pattern to return "void"? I mean in order to be "real Visitor pattern" as DoFactory (GoF) describes it, or it can be any return type and can still be called "real