Javascript Design Patterns #8 - Visitor Pattern

preview_player
Показать описание
What is the Visitor pattern?
The Visitor pattern allows you to add or define new functionality to an object without changing the code for that object. The new logic resides in a external object or function called the 'visitor'.

Visitors are useful when you are trying to extend the functionality of a library or framework. If the object you want to extend provides some kind of 'accept' method that accepts a visitor object/function, you can grant the visitor object access to the receiving object's internal properties. The visitor can then modify the behavior of the receiving object. This pattern allows you to provide an easy way for clients to implement future extensions to that object.

📚Materials/References:

🌎 Find Me Here:

Рекомендации по теме
Комментарии
Автор

I was going to sleep but then I came across a video of yours and binge-watched all the videos in the Tutorials playlist. And it is 3.30AM.
So, awesome work!!

GauravBoraJodhpur
Автор

Overall good video, though I would just say be careful when doing Employee.prototype = { getFoo: function () { ... code ....}}; as this will overwrite the original prototype reference! It’s safer to do Employee.prototype.getFoo = function ()

amerikan
Автор

I happy that I "visited" DevSage!

neuodev
Автор

I've been struggling to understand this, thanks a lot!

beastblack
Автор

Amazing videos. Very nice explanations. Would like you to consider making a video on composite pattern

aniketpaul
Автор

I went to watch this video and realized I'm watching it at the exact same time it was recorded 2 years later. 3:28 PM on December 7th

yshuttle
Автор

Is there a particular reason that you always do JavaScript OOP using the prototype method vs class kw? I like what you are doing —continued Success 👍🏾💯👌🏾

Chris-qgkc
Автор

very cool, thanks for shering, exellent channel!!!

mocwgoc
Автор

Thank you very much. Now it is very clear how this pattern works, but I am still a bit confused about its use case.

ratias
Автор

Hey, greeting from Bulgaria. Thanks for making this videos. Your explaining stuff really good.

My request is. Can you make videos for the PubSup and Mediator patters. ^^

georgidimitranov
Автор

What is the benefit of this over simply writing:

devsage.salary = devsage.salary * 2;

Right? We just changed the internal state of an object instance of a constructor function. What did we achieve?

I'm sure there is a point to it, and it is useful in some situations.
However, I didn't understand why we did it.

gkarapeev
Автор

How do you feel about making a video on javascript prototypes?

octaviusbytes
Автор

Nice tutorial. I’m trying to think about a practical use case for this. Is this scenario valid.. The Employee class is manipulated by the HR department who hires employees, logs their information and such. The ExtraSalary class is handled by the Finance department?

PhilanJames
Автор

lowkey thought this was a fireship video

baxi
Автор

Hey man great video but do you think solving this with class that came with ES6 is simpler.

karthickdurai
Автор

var DevSage = new Employee('DevSage', 10000);
// 1000

function doubleSalary(DevSage){
*2) ;
}
doubleSalary(DevSage);
//2000

We can also call this way,


Can you please telll me why do we need accept method here ?

javascriptduniya