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

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 มิ.ย. 2024
  • Learning system design is not a one time task. It requires regular effort and consistent curiosity to build large scale systems. Moreover, every system has different requirements and meeting them requires expertise and people with varied and specific knowledge. There are a lot of resources to learn through videos. But not everyone enjoys that mode of learning. Instead some people understand things better by reading and thinking on the points put forward by the author. Such people can access these in different ways - blogs, articles and books. We have come up with this video to put light on one such aspect, that is - Low level Design for developing an admit card module for an app that generates admit card for various different universities.
    Important links and resources:
    ✒ github.com/topics/low-level-d...
    ✒ Quick summary: docs.google.com/document/d/17...
    ------------------------------------------------------------------
    Recommendations
    ------------------------------------------------------------------
    Our full courses on youtube:
    ✒ System Design Primer Course: • System Design Primer C...
    ✒ REST APIs made easy: • REST APIs MADE EASY
    Some paid courses that we recommend:
    ✒Educative.io: bit.ly/3qnW5ku
    ✒Interviewready.io: get.interviewready.io/ (Use coupon code SUDOCODE for extra discount)
    ------------------------------------------------------------------
    About Us
    ------------------------------------------------------------------
    Created and Instructed by:
    Yogita Sharma
    ✒ LinkedIn - / yogita-sharma-83400b55
    ✒ Instagram - / sudo.code1
    ✒ Facebook - / sudo.code
    ✒ Medium - / yogita088
    Post-production(editing, thumbnail etc) managed by:
    CiKi
    ✒ Website: www.ciki.co.in
    ✒ LinkedIn: / 74735937
    Colors and design by:
    Naini Todi
    ✒ LinkedIn - / nainitodi
    Both Arpit and Yogita are software engineers and want to help other software engineers become better by providing high quality and well researched content by adding their creativity and teaching twist.
    ------------------------------------------------------------------
    Join Us
    ------------------------------------------------------------------
    Hangout with sudoCode:
    ✒Discord Server: / discord
    For business:
    ✒Email: sudocode.yogita@gmail.com
    Timestamps:
    0:00 - Intro
    0:30 - Introduction to Singleton Design Pattern
    3:03 - Analogy of PM's calender
    4:30 - Eager loading vs Lazy loading
    5:40 - Code walk-through
    10:58 - Summary

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

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

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

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

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

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

    you are the best for DP lectures

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

    Great work

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

    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.

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

    Excellent !

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

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

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

      Glad to hear that

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

      why not make the global variable final 1:52@@sudocode

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

    thanks a lot for the video

  • @saumitrasaxena8470
    @saumitrasaxena8470 ปีที่แล้ว +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 ปีที่แล้ว

    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  ปีที่แล้ว +1

      Great to hear!

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

    very nice video

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

    Nice

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

    Your videos are Dope

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

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

    • @sudocode
      @sudocode  ปีที่แล้ว +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 👍

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

    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

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

    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

  • @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 ?

  • @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.

  • @abhishekpatyal7480
    @abhishekpatyal7480 ปีที่แล้ว +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 ปีที่แล้ว +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 2 หลายเดือนก่อน

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

  • @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?

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

    👌👌👌👌👌👌

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

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

  • @saumitrasaxena8470
    @saumitrasaxena8470 ปีที่แล้ว +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 6 หลายเดือนก่อน

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

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

    What do you mean by thread safety?

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

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

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

    🙏🙏🙏

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

    ❤❤❤

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

    How to book appointment of PM in the given example?

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

      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.

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

    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 11 หลายเดือนก่อน

      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.

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

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