Story of Singleton Design Pattern and a Prime Minister | LLD Series | Low Level Design |

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.ย. 2024

ความคิดเห็น • 40

  • @user-yt8xf2xf7c
    @user-yt8xf2xf7c 4 หลายเดือนก่อน

    Spent Hours and hours to learn the concepts. Finally I found my peace. Thank you very much . Great Stuff!

  • @yaad122
    @yaad122 2 ปีที่แล้ว +2

    Well Done and keep it up, I am improving day by day by watching all these great videos.

    • @sudocode
      @sudocode  2 ปีที่แล้ว

      Glad to hear that

  • @jatindersinghaujla
    @jatindersinghaujla 2 ปีที่แล้ว

    Great, very nice well informative video on design patterns. You guys make our learning more easier after watching these video I believe there is no need to read books. I am following you guys from 1 year almost and I have learnt a lot more from you, Gaurav sen, Kirti Purshwani, Kunal Kushwaha, Apna College guys and other. Keep on doing such a great work to teach us. Really appreciate your hard work.

  • @syit_346_adityaprajapati6
    @syit_346_adityaprajapati6 ปีที่แล้ว

    you are the best for DP lectures

  • @rahul-sinha
    @rahul-sinha 2 ปีที่แล้ว +3

    Great mam, please add here more videos on other design patterns as well.
    Thank you 😊👌

    • @sudocode
      @sudocode  2 ปีที่แล้ว +1

      I will try my best. Some will be coming soon

    • @prashantrajawat2829
      @prashantrajawat2829 ปีที่แล้ว

      Mam please complete remaining video of solid principles. Your explanation is amazing 👍

  • @saumitrasaxena8470
    @saumitrasaxena8470 2 ปีที่แล้ว +1

    Hi ,Its good explanation and would appreciate if you would have shown like how initial code can be broken by refelction and then do the needful , and then like how code is not thread safe by generating two threads and changing value via threads.Hoping to see the same later videos

  • @lapimpale
    @lapimpale 2 ปีที่แล้ว

    Thank you for eager loading and lazy loading. After watching multiple singleton videos I was confused why there was difference. I thought it was just coding style of that individual so never googled it too. Now I am clear :) and can also explain interviewer.

    • @sudocode
      @sudocode  2 ปีที่แล้ว +1

      Great to hear!

  • @abhishekpatyal7480
    @abhishekpatyal7480 2 ปีที่แล้ว +2

    Hi Yogita, Awesome video. Thank you so much for explaining the Singleton pattern so smoothly.
    However At 7:12, I think there is a slight correction to be made. I think the implementation is thread safe because we are creating the object as soon as application starts. So, it is thread safe.

    • @this.arunsaini
      @this.arunsaini 2 ปีที่แล้ว +3

      right and with that ... last point of cons... the inconsistency part. If the singleton is initialized and more than one thread is using it then it will remain consistent since we cannot change the data after initialization.

    • @AbhishekKumar-yv6ih
      @AbhishekKumar-yv6ih 5 หลายเดือนก่อน

      Right, since we are not changing the data midway, reading through multiple threads won't take it to data inconsistency.

  • @lettry5297
    @lettry5297 2 ปีที่แล้ว

    Your every video is worth to watch. Please keep on adding such high quality content. 🤩

  • @sanketh768
    @sanketh768 2 ปีที่แล้ว +3

    We can declare logger as final, then nobody can change its value

  • @Sdirimohamedsalah
    @Sdirimohamedsalah ปีที่แล้ว

    Smooth explanation thank you. I have tow questions
    1- a singleton pattern save memory ?
    2- could you please illustrate the last point how can we get unwanted behavior without using thread safe ?

  • @ALLINONETV1
    @ALLINONETV1 ปีที่แล้ว +1

    Nice

  • @vinodrajj
    @vinodrajj ปีที่แล้ว

    Excellent !

  • @terex1394
    @terex1394 11 หลายเดือนก่อน

    Great work

  • @rite2riddhi
    @rite2riddhi ปีที่แล้ว

    very nice video

  • @tolosricardos2111
    @tolosricardos2111 2 ปีที่แล้ว

    thanks a lot for the video

  • @saumitrasaxena8470
    @saumitrasaxena8470 2 ปีที่แล้ว +1

    Hi Yogita , This singleton class can be breaked using reflections.Also appreciate if you would have covered Reflection ,Cloning and Serialization which can break this Singleton contract.

    • @user-fg2iw4yi7q
      @user-fg2iw4yi7q 8 หลายเดือนก่อน

      For Reflection, there is a snippet in the video where the constructor is throwing RuntimeException if anyone tries to be smart using Reflection.

  • @amanraut5304
    @amanraut5304 2 ปีที่แล้ว +2

    👌👌👌👌👌👌

  • @mdnadeemasgar6279
    @mdnadeemasgar6279 ปีที่แล้ว +1

    Hi Yogita, can you please upload the code online and share the code url in the description. So that we can also try manipulating the code for the given design pattern.

  • @umeshnaik844
    @umeshnaik844 ปีที่แล้ว

    Your videos are Dope

  • @SS-sn4df
    @SS-sn4df ปีที่แล้ว

    why cant we use a "final" keyword to avoid overriding problem with the global variable?

  • @colinmaharaj
    @colinmaharaj ปีที่แล้ว

    So I have been doing coding for over 20 years, but I never really understood design patterns. You mentioned thread safety as part of this Singleton pattern, but thread safety is a particular technique in coding, and syntax may vary between compilers.
    So how can this be part of a pattern?
    I'm now watching the whole video, I'll comment after watching in it's entirety.

    • @colinmaharaj
      @colinmaharaj ปีที่แล้ว

      Interesting, there are many variables that I usually keep as global, e.g. company name, and the only time it is written to is during application startup or during a config form dialog. During configuration , a multi threaded report, or a multithreaded schedule can kick in, and do a read-only on the variable. I do not have many writers for this variable, and only one person is allowed to configure the app.
      In my humble opinion, I will not do a singleton factory for that one variable, in fact I have hundreds of global variables that represents settings in my application, and the principle remains the same, only the configuration screens are allowed to write to these variables, or the first time loading process. So I think it is overkill to create a singleton factory to serialize access per variable.
      I am not saying the concept is bad or useless It's just appears to me to be overkill for hundreds of my variables because of the way my app will access them.
      Note that I use C++ Builder with 32 bit compiler turned on. I will do a 64 bit CLANG compiler from time to time.
      Now I do have routines, that is doing low level communications to a serial port or to a tcp socket. There is a reader routine and a writer routine.
      The writer routine, runs in a thread and waits for data from the serial port or tcp socket. These operations are usually blocking, so this is why I placed them in a thread.
      The fore-ground application, reads data from blocks of memory, that the writer writes to. In cases like these, I have a serializing agent, to make the writes and reads thread safe. There is only one writer and there is only one reader. The data structure that is being written to is a circular buffer.
      The writer will make the buffer length grow, and reader will make the buffer length reach to zero.
      Very recently, I wrote a process calling agent, to monitor an application called plink.
      The idea was to take the output of plink and have it write to my thread safe circular buffer.
      My fore ground routine would see if there is data in the buffer, empty the buffer and print it to the screen.
      If no data is produced within a period of time, the called process, plink, is killed.
      There is a situation where plink appears to hang, without any output being created, and does so indefinitely.
      So in this case I use my thread safe circular buffer to get data from plink. Plink is an ssh console app that writes to the screen. Once plink finishes within a reasonable time, the application closes itself, and the process handler is released. If plink appears to hang, my calling process kills the app and prints an error to the screen.

  • @mysterionetwork7849
    @mysterionetwork7849 7 หลายเดือนก่อน

    When you say you have attached link in the description (here for volatile keyword) I am not able to find it, not sure if I am looking at the wrong place

  • @himeshgupta6478
    @himeshgupta6478 5 หลายเดือนก่อน

    Can we make the global variable final in Java that solves the issue of getting it updated? Also why are we stressing about thread synchronisation when all the threads are going to read this variable once created no write updates allowed so no race condition

    • @soomann2716
      @soomann2716 29 วันที่ผ่านมา

      In lazy loading...any thread running will either create the object or use it.....Suppose two thread try to access the getInstance method at same time....without using synchronized...both will read instance==null so both will create new instance of class....but in synchronized it works like key and lock...if any thread goes inside synchronized it puts lock so that no other thread can get inside it...unless the thread has been completed and release the lock...
      Also feel free to correct me if I am wrong anywhere or ask any

  • @harshi993
    @harshi993 7 หลายเดือนก่อน

    What do you mean by thread safety?

  • @santoshr4212
    @santoshr4212 ปีที่แล้ว

    why would we have DB connection as singleton? are we going to use one open conn for all requests? If yes, is it ok to have a conn open?

  • @surya219
    @surya219 2 ปีที่แล้ว +1

    How to book appointment of PM in the given example?

    • @chethan93
      @chethan93 2 ปีที่แล้ว

      Consider PM's calendar is the object. Singleton pattern makes sure everybody gets a common instance of it. Then the calendar can have methods to book slots in it.
      Booking slots must also be synchronised here.

  • @rahultej8352
    @rahultej8352 11 หลายเดือนก่อน

    ❤❤❤

  • @terex1394
    @terex1394 11 หลายเดือนก่อน

    🙏🙏🙏

  • @kalyanroy6687
    @kalyanroy6687 ปีที่แล้ว

    If a global variable is a const/final, it can't be modified