Singleton Pattern - Design Patterns (ep 6)

Поділитися
Вставка
  • Опубліковано 19 січ 2025

КОМЕНТАРІ • 493

  • @mphophantshang9087
    @mphophantshang9087 5 років тому +427

    Boss: My wife is cheating on me
    Programmer: One man's constant is another man's variable....

  • @mohammadnaseri5045
    @mohammadnaseri5045 7 років тому +189

    One of the best series I have ever watched. Keep going on dude!

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +8

      mohammad naseri thank you for the kind words. I'm glad it's useful :)

  • @IamCagedAnimal
    @IamCagedAnimal 6 років тому +15

    U, my good Sir are born for teaching, really nice and simple explanation for everyone to understand. Keep up the good job!
    cheers

  • @dalitsobotha7932
    @dalitsobotha7932 4 роки тому +1

    I love the way you teach. Your explanations are thorough and the way you speak is very captivating. Straight to the point, you are not a time waster.

  • @Tapuck
    @Tapuck 7 років тому +12

    Your editing is absolutely fantastic. The stream of knowledge never stops or slows down.

  • @vineetherenj3143
    @vineetherenj3143 4 роки тому +100

    Me: Let me learn about Singleton pattern.
    Christopher: never use singleton pattern.
    Me: -_-

    • @eugeneganshin2934
      @eugeneganshin2934 3 роки тому +1

      You can use it tho. In Typescript Nestjs Framework alsmost every class is a singleton and its fine.

    • @PeterFlemmingNielsen
      @PeterFlemmingNielsen 3 роки тому +3

      You should never use it, except when you should. (eg. it is good to prevent database connection leaks)

    • @AlonGvili
      @AlonGvili 3 роки тому +1

      @@eugeneganshin2934 so like redux store is a singleton in a javascript/react world ?

  • @SaurabhGuptaicecool
    @SaurabhGuptaicecool 4 роки тому +2

    This series is greatest I've ever encountered on youtube on any topic, period.

  • @hoelefouk
    @hoelefouk 5 років тому +5

    If there is anything comparable to your teaching skills, it's your skills to have amazing intros. Intro for this particular video is simply genius. Your intros are so underrated man!

  • @ruvishkarathnayake9125
    @ruvishkarathnayake9125 5 років тому +2

    The way you teach these lessons is perfect. This is a good example for my lecturers how to teach these stuff.

  • @karzo222
    @karzo222 4 роки тому +1

    You are criminally underrated. Deserves more followers. Top notch.

  • @prapulkrishna
    @prapulkrishna 4 роки тому

    You are one of the best teachers on the planet. Thanks for the videos.

  • @mikhailbisserov
    @mikhailbisserov 7 років тому +56

    That's a good video. Especially the code smell part. I would add though that to ensure single instance you also need to wrap instance creation with lock (Monitor), because nowadays threads are used left and right. In fact, "double-checked locking" (that's a pattern) should be used
    if (instance == null) {
    lock (_lockObject) {
    if (instance == null) {
    instance = new Singleton();
    }
    }
    }

    • @GohersWay
      @GohersWay 4 роки тому

      Sorry for asking such a newb question but what is purpose of locking here.

    • @mikhailbisserov
      @mikhailbisserov 4 роки тому +12

      @@GohersWay Locking prevents execution of the enclosed code by multiple threads. We want "instance = new Singleton()" execute only ONCE in entire process lifetime and for that we need to make sure that inner "if (instance == null)" is never evaluated SIMULTANEOUSLY (but theoretically it can happen more than once, if two threads happen to access the singleton instance for the FIRST time simultaneously). Now, why do we need outer "if (instance == null)" - because it's much cheaper than lock in terms of CPU. If a web application runs for 30 minutes before process recycling, then 99.9% of instance access cases by different threads will go no further than outer if, 0.09% will create monitor, wait on that monitor, and evaluate inner if, and 0.01% will actually execute inner if's enclosed code (instance = new Singleton).

    • @good_life_videos
      @good_life_videos 2 роки тому

      @@mikhailbisserov but even if two threads access that part of creating the object, why should it be a concern ? considering, first instantiation call is just necessary (but state will always be random, so hardly matters who creates it finally or been changed by some other threds at same time)

    • @mikhailbisserov
      @mikhailbisserov 2 роки тому +3

      @@good_life_videos if two threads create instances of the object, it's not Singleton by definition. WHY we want to create it only once is an out-of-scope question. It's a given task, purpose of Singeton. Usually it's for performance and memory conservation, maybe even acquiring lock to some unique underlying resource, but again, it's out of scope.

  • @jaycelila6258
    @jaycelila6258 7 років тому

    don't understand why this video is not popular than it has to be. You are amazingly well explaining abstract concepts so dumb like me can understand. Thanks.

  • @clementtytube
    @clementtytube 3 роки тому +1

    First time seeing your videos... I give a 10000 likes for your cuts and edits. Your videos are full of info (no lags and time waste). That itself proves you value your trade.. Kudos

  • @sammclaren6965
    @sammclaren6965 Рік тому

    That's what I call 'in-depth explanation'! Awesome work.

  • @ckmedia6120
    @ckmedia6120 5 років тому +3

    This is why I love the internet, good videos with good info. My man!

  • @ariaien8637
    @ariaien8637 5 років тому

    Singleton design pattern is simple, however, complicated! every line of the code was explained thoroughly and beautifully.. well done! One of the best videos ever for Singleton!

  • @CognitiveSurge
    @CognitiveSurge 7 років тому +40

    Love these videos, thanks Christopher! The Head First series is great.

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +1

      Karl Hadwen thanks! I'm very glad they're useful. Thanks for watching :)

  • @rusiraliyanage6643
    @rusiraliyanage6643 4 роки тому

    Hey SIr , I am Sri Lankan IT Undergraduate , you do explain these design patterns very well and Thank You So much. It was really helpful me to figure out the answers for the design patterns questions in our university :)

  • @oussamaml4161
    @oussamaml4161 6 років тому

    i got a UML exam tomorrow , and i've been watching your video , your videos are saving my life right now

  • @DAS-jk3mw
    @DAS-jk3mw 2 роки тому

    This is the best explanation of a Singleton pattern ever !!

  • @aniketb2010
    @aniketb2010 6 років тому +10

    “One man’s constant is another man’s variable”... Woow!!

  • @seguncodes3136
    @seguncodes3136 3 роки тому

    The best explanation of Singleton pattern i have come across

  • @sibinM11
    @sibinM11 3 роки тому

    this guy and explanation is pure gem

  • @kirubababu7127
    @kirubababu7127 4 роки тому +1

    The way you teach is fantastic, you are my inspiration.

  • @timothyjohns8775
    @timothyjohns8775 6 років тому +9

    Not sure about other languages, but in C++, the preferred approach to singletons is known as the Meyers Singleton (named after Scott Meyers who included it in his book Effective C++). The idea is to declare the variable within a method rather than as a member variable. This is thread safe, and it also allows you to skip the check to see whether or not the singleton exists. The code looks like this:
    class Singleton {
    private:
    Singleton() {}
    public:
    static Singleton& getInstance() {
    static Singleton instance;
    return instance;
    }
    };

    • @yoavmor9002
      @yoavmor9002 Рік тому +1

      I don't think intra-method static variable magic exists in non C languages, I think it's mostly a C thing. By the way, I'm assuming you meant static Singleton instance = new Singleton()

    • @Remist0
      @Remist0 Рік тому +1

      @@yoavmor9002 It's not a pointer, so they did not mean that.

  • @sushantkumar1845
    @sushantkumar1845 3 роки тому

    The best playlist (on IT/Sw) I have ever watched on UA-cam

  • @gurituna
    @gurituna 7 років тому +1

    Excellent i have a java architecture certificate exam within 3 months. You made me clear with the design pattern. Many thanks. Bless you

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +1

      +gokhan tuncel I'm glad to hear. Thank you very much for sharing and best of luck on the exam :)

  • @gavinmcgregor3219
    @gavinmcgregor3219 7 років тому +4

    Just wanted to let you know that you are amazing for making this series!

  • @ShobhaMahadev-x5y
    @ShobhaMahadev-x5y Рік тому

    A clear video on single ton design pattern. Thank you.

  • @johnyjohnjohny8014
    @johnyjohnjohny8014 7 років тому +2

    This is quality man. Keep the good work, youtube definitly needs that. Well done

  • @luli829
    @luli829 7 років тому

    Already learned this in university and now planning to review again, my professor who teaches that course is very good, and your lecture is as good as the course I learned before ! Thank you so much ! Waiting for more

  • @jvsnyc
    @jvsnyc 3 роки тому

    The Clean Code links are all great! Now, back to your videos! I wound up learning as much from this as any of your others in this playlist, thanks to the excellent links provided in the description. Singletons seem very convenient, until test-time...

  • @vyaasshenoy1884
    @vyaasshenoy1884 6 років тому +1

    Your explanation is clear and precise. I enjoyed the video and was able to understand the nuances of this pattern very well.

  • @lyusienlozanov1632
    @lyusienlozanov1632 7 років тому +3

    Everything makes sense with that kind of explanation! Thanks, Chris!

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +1

      Thank you for the very kind words. Much appreciated and I'm glad to hear it. Thanks for watching :)

  • @AVBFANS
    @AVBFANS 7 років тому +1

    great video. finally I found explanation in a style that I can understand clearly. Thanks for the lesson. I am now a subscriber.

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +1

      +AVBFANS Awesome! Welcome to the channel :) And thank you for sharing your thoughts :)

  • @IntelliAbb
    @IntelliAbb 7 років тому

    As much as we try to avoid Singletons, we do run into scenarios where we have to use one. Specially when working with native Android using Java where for creating Fragments, we use a public Instance property to get access to it. These Instances are then held in memory for various operations done by the OS.
    Great series, keep it up :)

  • @thomas2957
    @thomas2957 6 років тому

    You're views must really go up every December/January. Exams time and your explanations are great, thanks man

  • @sarahlee6976
    @sarahlee6976 2 роки тому

    BEST VIDEO EVER!!!!! So much better than university lectures

  • @betterculture
    @betterculture 7 років тому +9

    Great video! However, the argument is not that Singletons are necessarily bad except that they are misunderstood, often abused and can introduce unwanted side effects when used without proper thought -- a lot of frameworks use Singletons :D.
    For instance, I have this piece of (framework) code that manages all of my configurations (and of subsystems) and the construction of this object is really heavy and doesn't even lend itself to a prototype or flyweight. It is important that these bits of configuration happen only once at application startup. Instead, I hide my singleton configuration instance behind an abstraction and delegate the construction and life cycle to a DI / IOC container. In other words, users only have to depend on that abstraction e.g. IConfigurationManager etc.
    In addition, the one thing (or two) I think you're missing is the issue of potential race conditions or thread-safety in concurrent systems when handling stuff like this manually -- why it's important to use a good DI framework and instead depend on abstractions. Plus, it is your responsibility to ensure that your object is IMMUTABLE upon construction and member access is read-only.

  • @Wwise_sounds
    @Wwise_sounds 2 роки тому

    SNHU is using this video as material reference. you should feel proud that an university is using your videos to teach new students :)

  • @rustemduran4248
    @rustemduran4248 2 роки тому

    NIce man, totally grasped for the first time, thank you so much.

  • @gg4eva763
    @gg4eva763 3 роки тому

    Oh my god, you are a good explainer! I'm actually understanding what's happening

  • @pervanadurdyyeva1920
    @pervanadurdyyeva1920 3 роки тому

    Simplest and clear explanation I've come across. Thanks

  • @mehakjain5384
    @mehakjain5384 7 років тому +6

    One of the best video series I have ever seen. Superb explanation. Quite like the way you do these videos in your own style. Keep up the good work.
    P.s. loved ur writing and honesty :P

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +2

      Thanks! I'm glad to hear that the style works :) Thank you for the encouragement and for watching the series :)

  • @sumitkapadia1509
    @sumitkapadia1509 7 років тому +5

    The way you jump entered, I expect to hear "Hey Vsauce" :P . Awesome video.

  • @Death8ball
    @Death8ball 7 років тому +1

    Fantastic series. When I get my first dev job I will do what I can to support you.

  • @glenndify1
    @glenndify1 7 років тому +2

    you have really simplified design patterns ... classic explaination ... thank you very much

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому

      +Glenn Dsilva Thanks for letting me know! :) And thanks for watching!

  • @kensearle4892
    @kensearle4892 Рік тому

    Thank you! Good points.
    The only time I have used a Singleton is when I was developing my own small website, wanted a quick cache, and only needed to load the database once at application startup to save on Cloud Database DTU hits. The webpage did load faster using the Singleton as a cache. A static class also worked for this scenario and is a little more straightforward. Either was ok for this scenario because I only changed the data about once per month, could restart the application when I wanted, and didn't have sessioned users on the site yet.
    However, once I want to add/change data in the database and want to reset the cache without an app restart, it is a dead-end; so it is not practical for many business production scenarios.
    I was just looking at 5-6 ways to cache and those were the quickest but most limited.

  • @N1ghtR1der666
    @N1ghtR1der666 4 роки тому +2

    definitely a very simple to understand explanation, thank you. I would as "a novice" suggest there are legitimate uses for singletons in game development.

    • @PatrickMagToast
      @PatrickMagToast 2 роки тому

      Could you provide an example, now that you've grown another year? :D I mean ofc there are things like "auto-saves" you need only once, but would there be a need to access them globally? It prevents people from doing stupid things but at the same time allows them to do other stupid things.

  • @radekp9851
    @radekp9851 7 років тому +200

    if one is a religious fanatic and assembles a God class, singleton pattern seems like an obvious choice :)

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +16

      +Radek P This comment is quite simply hilarious :D :D

    • @pradeeph2000
      @pradeeph2000 7 років тому +10

      Radek P LOL!!! For Indian Hindu fanatic it's probably a fly weight pattern with millions of fly weights

    • @timmyers9798
      @timmyers9798 6 років тому +14

      Unless you have more than one god, then you have to refactor the whole universe.

    • @Quynn-Oneal
      @Quynn-Oneal 6 років тому +4

      have you ever heard about Polytheism?

    • @uzil24
      @uzil24 6 років тому +8

      don't you mean polymorphism? ;-)

  • @uzil24
    @uzil24 6 років тому +1

    Thank you for this video and all the rest. I really hope to find every single Design pattern explained by you in this play list.

  • @liveyounganastasia
    @liveyounganastasia Рік тому

    I love how you explained this. Very clear. 👏

  • @exoticcoder5365
    @exoticcoder5365 3 роки тому +1

    Gooooooooood one !!!! Very clear ! Clear all my concepts !

  • @miguelangelocano9918
    @miguelangelocano9918 Місяць тому

    @Christopher Okhravi, what about spring singletons?
    Feature: Thread Safety
    Manual Singleton: Must ensure explicitly (e.g., static inner).
    Spring Singleton: Handled automatically by Spring.
    Feature: Ease of Use
    Manual Singleton: Requires boilerplate code.
    Spring Singleton: Simpler and more declarative.
    Feature: Testability
    Manual Singleton: Hard to mock.
    Spring Singleton: Can inject mocks using DI in tests.
    Feature: Flexibility
    Manual Singleton: Hard to replace or extend.
    Spring Singleton: Can configure beans dynamically.
    Do you see it as avoidable and violating best practices and principles?

  • @naffiahanger9316
    @naffiahanger9316 3 роки тому

    Your explanation of concepts are easy to understand 👏👏👏👏👏

  • @slobodanmikaric2180
    @slobodanmikaric2180 7 років тому

    Singleton can be used in notification servers for mobile devices or others, when you always have one and only one instance to call to add or remove observers. :) thx Christopher Okhravi for clearing this out!

  • @VaibhavJain
    @VaibhavJain 5 років тому

    Liked the way you describe different aspects of decision making and assumptions related to pattern

  • @cunami2
    @cunami2 7 років тому +1

    Amazing work on patterns, reading book is fine, but all those extra explanations are just making everithing perfectly fit in place. Wish you could finish rest of book till monday when i have test out of all patterns from book ^.^
    Any way, keep it up (sharing videos with rest of Uni, everyone is gratefull)

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому

      +cunami2 thank you very very much for sharing the video :) Increasing views and comments like yours are of course things that keep me going :) :)

  • @heshamabood472
    @heshamabood472 3 роки тому +1

    Singleton pattern is useful in a situations like when need create a logger for the application, this case required only one instance to be instantiated and used by multiples modules

    • @EngSamieh
      @EngSamieh 3 роки тому +1

      In general, most HW devices don’t allow concurrent access, Singleton pattern is essential to provide the SW interface that encapsulates the protection for the HW device.

  • @taki5baj
    @taki5baj 5 років тому

    As I saw your video I get the feeling that I never ever understood clearly the Singleton design pattern. Your video catched me like 'Yeah, this stuff doesn't do much more than a static class.' Then my brain went on fire, I started thinking about this. Then I came up with a 'reason': A static class's constructor (type initializer) can't have any parameters in it's constructor. Singleton pattern can have any parameters, that the constructor might need in the getInstance() method. 1: Simply initialize an object, with the given parameters 2: Simply override the fields to the parameters.
    The only use-case with a Singleton pattern I can think of is like focus on a UI element (or GameObject if we are talking about a game). Just pass the object as a parameter and the singleton might change the color of the passed object to red, so only the element will be in focus. Sorry if this is wrong, I'm still a beginner in programming.
    C# example:
    public interface IFocusable
    {
    Color ObjectColor{get;set};
    }
    public class Button : IFocusable
    {
    public Color ObjectColor{get;set;}
    public Button(){.....}
    }
    public class FocusSingleton
    {
    public static FocusSingleton instance;
    private IFocusable focusObject;
    private Color oldColor;
    private FocusSingleton(IFocusable objectToBeInFocus)
    {
    focusObject = objectToBeInFocus;
    oldColor = objectToBeInFocus.ObjectColor;
    objectToBeInFocus.ObjectColor = Color.Red;
    }
    public static FocusSingleton getInstance(IFocusable newObject){
    if(instance == null)
    instance = new FocusSingleton(newObject);
    else{
    focusObject.Color = oldColor;
    oldColor = newObject.ObjectColor;
    newObject.ObjectColor = Color.Red;
    }
    return instance;
    }
    }
    If this would be done with a static class, then we should check @ every object dependent method if the focusObject is null. With Singleton the checkings are eliminated.

  • @irshuck
    @irshuck 7 років тому +2

    Woooow, Thanks christopher for this wonderful series. Your teaching style is awesome. waiting for other design patterns :)

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому

      +Irshad ck Thank you. Makes me glad to hear. Next one is coming very soon. Thanks for watching :)

  • @m41kdevelops41
    @m41kdevelops41 6 років тому +8

    Great videos.
    I just have an opinion and feel free to correct me; I believe that the Singleton pattern could be used for things that we only need one of such as database connections for example.
    So throughout the application's run-time, I don't think we'll need to change or re-establish the connection to the database we're using ( unless it is necessary for some reason of course ) so I think it's best to only allow one instance of the db connection class and each time we request an instance ( potentially a new connection ) we just send the existing connection back.
    please feel free to correct me if i'm wrong.

  • @abhishekpawar8458
    @abhishekpawar8458 11 місяців тому

    Thanks for this amazing video. One correction I would suggest is to make the static getInstance method synchronized. In the world of multi-threading, if two threads access the getInstance method, they will end up with 2 different instances

  • @rajeshrathod9329
    @rajeshrathod9329 7 років тому

    Very nice and detailed explanation of design pattern concepts.... I am waiting for other remaining design patterns videos ..... Thank you very much.

  • @gargkapil
    @gargkapil 7 років тому +1

    Hey Christopher it was a nice video but i have couple of question please try to answer them whenever you get time..
    1. what is the main difference between singleton and static class about which developer usually don't know.
    2. Under which scenario we should use static class and when should we use singleton pattern.
    3. if i have a abstract class having all abstract method and I have an interface, then which one i should choose and why??
    I have couple of more questions which i ask you once i will get the clean and deepest answer of these question.

  • @Metachief_X
    @Metachief_X 5 років тому

    god bless you, christopher. Please keep making videos!!

  • @MrTrik15
    @MrTrik15 5 років тому

    Clear, audible video. Keep it up

  • @mark7166
    @mark7166 4 роки тому

    One valid reason you might want to use a singleton would be in an app where a lot of lookup data is shared throughout. It makes sense to have a single instance of a class which loads the data once the first time it's needed, and then makes it available in all subsequent places without having to make another call to the database.
    Other than that, there certainly doesn't seem to be many reasons you'd want something like this.

  • @lindawisebear
    @lindawisebear 4 роки тому

    It was really helpful that you went through the code in this video; great series! :)

  • @stefanoforgiarini339
    @stefanoforgiarini339 6 років тому

    Excellent explanation Cristopher! Only one thing to note: what happens in a multi-threaded environment? It may happen that two different threads call the getInstance() method and because of this, more than one instance of the Singleton class is created. The only way to ensure a single instance is to add the synchronized in the getInstance method signature or (it would be better), synchronize the block of code in which we check if the instance is null (the if statement).
    Congrats for your videos!

  • @mhshbht12
    @mhshbht12 7 років тому

    very good explanation of Singleton. Thanks Christopher

  • @DominikRoszkowski
    @DominikRoszkowski 7 років тому +10

    Thanks, your explanation was clear and convincing :)

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +1

      Dominik Roszkowski thanks for sharing and for watching :)

  • @kasunperera9700
    @kasunperera9700 6 років тому

    thanks chrostoper the best video about singleton i ever watched

  • @emskiee5330
    @emskiee5330 5 років тому +7

    I love Singleton in Unity. Very handy for Manager objects.

    • @TheLucausi
      @TheLucausi 4 роки тому +1

      It could become your worse nightmare xD

    • @emskiee5330
      @emskiee5330 4 роки тому

      @@TheLucausi I've actually seen it unfold before me when the project I am working on became large. The Manager became this class with lots of states. Singleton, despite being great for Manager objects, should still be used sparingly :D

  • @priyankmungra29
    @priyankmungra29 3 роки тому +1

    Thank you for making this series ❤❤❤

  • @ZenMonkIlya
    @ZenMonkIlya 4 роки тому

    Very informative! Thank you very much for this fantastic explanation, and for presenting it in such a good-natured way!

  • @johanbln
    @johanbln 3 роки тому

    Super video! I will never forget what is a Singleton :-)

  • @praveennampelly3559
    @praveennampelly3559 3 роки тому

    Superb man, you explained very well. I really got lot of interest on design patterns. Thank you so much I leant a lot from your video's.

  • @sachinkainth9508
    @sachinkainth9508 3 роки тому

    Very great video. Thank you for this. One thing that is missing is a discussion about a thread-safe version of the Singleton pattern using double check locking or some other mechanism to achieve thread-safety.

  • @mayankgupta4243
    @mayankgupta4243 7 років тому

    Thanks Christopher really your explanation is very good

  • @zolisawelani9338
    @zolisawelani9338 4 роки тому

    Super awesome mate. Clear explanation.

  • @MultiAkash1988
    @MultiAkash1988 4 роки тому

    Love u sir, U make design pattern so easy

  • @SantanPereira
    @SantanPereira 7 років тому

    I have watched all your videos on Design Pattern, You rock!!! keep up the good work. :)

  • @always90s
    @always90s 7 років тому +3

    Thanks Christopher! I will definitely check out those links. On to the next pattern :)

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому

      Hitesh Rana cool! They're worth the time. Misko seems like a very smart guy. Thanks for watching!

  • @kevinbenavides92
    @kevinbenavides92 7 років тому

    You are a great instructor. Keep it up please.

  • @biswarup077
    @biswarup077 7 років тому +2

    Great video. One suggestion: if you would have included multi threaded environment that would have been great. In many interviews this is asked.

  • @sakshisharma7097
    @sakshisharma7097 7 років тому +1

    Dude ! am waiting for command design pattern :) you are awesome , i just love the way u make everything easier and understandable :)

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +1

      +sakshi sharma thanks! :) I'm glad you're following the series. Thanks for watching and for the comment.

  • @ОлегТокмачев-в9ц
    @ОлегТокмачев-в9ц 6 років тому

    Thanks a lot! Very cool vivid explanations and examples! Thanks! Thanks! Thanks!

  • @JohnDoe-ej6vm
    @JohnDoe-ej6vm 4 роки тому

    such a wonderful lecture . concept clear now.

  • @魔鬼鱼-x4b
    @魔鬼鱼-x4b 3 роки тому

    Super clear! Thanks Christopher!

  • @vinoddurge8600
    @vinoddurge8600 7 років тому

    Great Series...Thanks for making those video ... waiting for more videos.

  • @egruper
    @egruper 7 років тому +1

    had to add - you are amazing! great vids once again Thank you.

  • @גלכהן-ו8ח
    @גלכהן-ו8ח 7 років тому

    That smile in the end.
    LOL
    Greate series ! Waiting for the next chapter!!

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 років тому +1

      :D :D

    • @yonishachar1887
      @yonishachar1887 4 роки тому

      בואנה יא ישראלי מה אתה עושה פה? אני הישראלי היחידי שמכיר אותו

  • @shleym
    @shleym 6 років тому +5

    Thank you. One note: singleton should be created in synchronized method, otherwise you could ended with more then one different instance of your singleton in different threads.

    • @ChristopherOkhravi
      @ChristopherOkhravi  6 років тому +2

      Or it should simply not be used at all 😋😉 Thanks for watching!

    • @blasttrash
      @blasttrash 5 років тому

      @@ChristopherOkhravi What about a Database class? Why need two instances? We can be 100% sure that our app will only need single instance in this case right?

    • @ChristopherOkhravi
      @ChristopherOkhravi  5 років тому +2

      blasttrash There’s always a second case: the testing environment 😊 Id recommend Misko Heverys clean code talks on UA-cam if you want to dig into this a bit more. But ofc its not all black and white and a database is as you say a pretty good candidate if you only interact with the DB singleton in predictable places such as controllers. If you call the database from lots of places in the app then we’re back to the testing problem :) And yes ofc there are solutions to test mocking singletons but that’s another story 😊

    • @pedroamaralcouto
      @pedroamaralcouto 2 роки тому +1

      @@blasttrash, I'm working professionally with several databases in a single REST server application. They're different databases for optimization reasons. If your program might grow and you force it to have a single database, your program might not be scalable.

    • @blasttrash
      @blasttrash 2 роки тому

      @@pedroamaralcouto that makes sense. But I think several databases in a single Rest server is an antipattern afaik. Not sure what optimization you are talking but most of blogs online say to have single database for most of typical rest apis. Only when you are doing some complex routing, sharding or dealing with different kinds of data(in which case might be better to have separate microservices anyway) do you need multiple databases.

  • @radoslavangelov7193
    @radoslavangelov7193 6 років тому

    Thanks for the really good video. I just found out these series and just cannot stop watching them! However, the Singleton is very used in languages like Ruby and Python. That's why I cannot agree it should be used nowhere. Maybe in Java and C it doesn't make a lot of sense but when you start understanding the meta programming in ruby for example, there is no way to not use the Singleton :)

  • @xavmanisdabestest
    @xavmanisdabestest 4 роки тому

    I think in a game manager would be the perfect time to use this pattern as you only ever have one instance of a video game so it could hold useful functionality there, but just like you said one mans constant is another mans variable.

  • @adityashekhar841
    @adityashekhar841 7 років тому

    awesome, its like a savior if you exams in next couple of hours.

  • @monjasonsteng7861
    @monjasonsteng7861 10 місяців тому

    This is perfect. Thank you so much.

  • @abedalrawas2656
    @abedalrawas2656 7 років тому

    These videos are so precious thank you!