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.
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
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.
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.
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.
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 ?
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.
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.
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.
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.
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
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
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
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.
Spent Hours and hours to learn the concepts. Finally I found my peace. Thank you very much . Great Stuff!
Well Done and keep it up, I am improving day by day by watching all these great videos.
Glad to hear that
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.
you are the best for DP lectures
Great mam, please add here more videos on other design patterns as well.
Thank you 😊👌
I will try my best. Some will be coming soon
Mam please complete remaining video of solid principles. Your explanation is amazing 👍
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
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.
Great to hear!
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.
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.
Right, since we are not changing the data midway, reading through multiple threads won't take it to data inconsistency.
Your every video is worth to watch. Please keep on adding such high quality content. 🤩
We can declare logger as final, then nobody can change its value
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 ?
Nice
Excellent !
Great work
very nice video
thanks a lot for the video
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.
For Reflection, there is a snippet in the video where the constructor is throwing RuntimeException if anyone tries to be smart using Reflection.
👌👌👌👌👌👌
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.
Your videos are Dope
why cant we use a "final" keyword to avoid overriding problem with the global variable?
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.
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.
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
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
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
What do you mean by thread safety?
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?
How to book appointment of PM in the given example?
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.
❤❤❤
🙏🙏🙏
If a global variable is a const/final, it can't be modified