Singleton Pattern - Design Patterns

preview_player
Показать описание
The singleton pattern is one of the most controversial yet easiest to implement design patterns. Many people say you should never use the singleton design pattern, but there are still plenty of cases where the singleton pattern is the perfect solution. In this video I will explain what the singleton pattern is, when you should and should not use it, and go over an example of refactoring some code to use the singleton pattern.

Design Pattern Playlist:

Design Pattern Repository:

Twitter:

GitHub:

CodePen:

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

Most of the NPM modules (major ones) uses this pattern, e.g: Mongoose. This pattern is one of the best if anyone is creating a library or something like that as you might need to output some debug information for the module. Great video thanks a lot....BTW thanks for changing your uniform

KallyanBRoy
Автор

to the point and really understandable! love it! keep up those great contents!

ardhiirfansyabani
Автор

This was pretty useful, i hope that your channel grows a lot in the next few months, you totally deserve it :)

thehardyboiz
Автор

Sometimes I wonder where I would be without you. 🙏🙏🙏

julescsv
Автор

its kind weird to see this smooth explanation regarding this subject because, most of times, some teachers don't really grasp this concept and makes this even harder... great content man... keep it up =)

fabriziotofanelli
Автор

your videos are awesome! thank you so much!!

Crazould
Автор

thanks a lot for your efforts , i really appreciate that

rahimco-susc
Автор

damn this has to be one of the best explanations i had with this pattern.

alejandroperezrivas
Автор

Is it a good idea to use singleton to simplify plugin methods, something like field.setValue(34); Then it's like a namespaced function where the plugin maker does not need to add new instances of the class.

jenstornell
Автор

Nice explanation, and use case, cheers. Do such singleton running on client side js commonly then persist their log array to db to allow after the fact debugging from one central place?

Carl-yuuw
Автор

Hi, The implementation looks good but In order to verify that the singleton implementation is working correctly you need to instantiate the FancyLogger twice, in your current implementation the constructor is called only once.

omarabid
Автор

Angular services are singleton by default, so I guess this pattern does have its niche

nabiisakhanov
Автор

The only video I found on youtube with 10K+ views and 0 dislikes...
For a long time, I was thinking guys at youtube randomly add dislikes to videos coz there are many good videos that got dislikes for no reason...

karthik-exdm
Автор

Ohshhhh, this is llifechanging. Thanks a lot.

audiodrocher
Автор

Why export an instance variable? Wouldn't it be the same if first and second file just call new, which would return the same instance and then move Object.freeze into the constructor? Thinking it would be a cleaner solution

klauspetersen
Автор

Can we use this instead of FancyLogger inside the constructor of FancyLogger?

vuejs
Автор

Hi Kyle, thanks for the video. I have a question regarding to this singleton pattern: what's the difference between using an instance 'logger' and using a 'static' class attribute in the class 'FancyLogger' to record the logs ?

penggao
Автор

I knew there was something I liked about You! Love the shirt. Any Zeppelin fan is a friend of mine. I'll shutup and sub, now.

Colstonewall
Автор

Great explanation, and thanks for the video, just have 1 question, is it really necessary to do this manipulations inside constructor, if we import instance of logger it will be same instance for any file because of modules that are singletones anyway? Just wondering why we really need that checks here?

tlev
Автор

Can we say that some parts of state managers like Redux use the Singleton Pattern?
Just to make sure I understood the concept here...

nalditrinmartinho