Singleton Design Pattern Tutorial

preview_player
Показать описание


Welcome to my Singleton Design Pattern Tutorial. The Singleton pattern is both easy to understand as well as useful. I'll demonstrate first how to implement the Singleton pattern. Then I'll provide and example of its usefulness with a Scrabble example.

Threads can sometimes play havoc with this pattern, so I'll show you how to avoid those problems. I'll also review how to use threads, LinkedLists and more.
Рекомендации по теме
Комментарии
Автор

Your thanks is all I require. I have no interest in money anymore so don't donate money. If you think others would like the site tell them about it and I'll be happy :)

derekbanas
Автор

Subject's explanation is crystal clear. Minor mistakes that mentioned in comments aren't that distracting. Thanks!

xipity
Автор

You're very welcome :) I'm using Eclipse right now so I can't test it, but yes I'm pretty sure if you just delete the code block with if(firstThread) you won't any problems. Give it a try. There won't be any hidden errors, you'll see what happens immediately

derekbanas
Автор

Never thought about the problems that could arise with threading. This is a beautiful tutorial. Thank you Derek.

Karthik-yyup
Автор

Your lessons are irreplaceable and exciting. Do not miss any elements of your personality. Keep calm and educate people.

arisapostoloy
Автор

Thank you :) It is always nice to hear that I cleared a topic up. No, I don't teach anywhere but on youTube. I plan on staying here for a while and everything will always be free.

derekbanas
Автор

You're welcome :) you use static classes when you are absolutely positive that every method will only be used in a utility type way. It is normally pretty easy to change a singleton if you require multiple instances down the road. That isn't true with a static class

derekbanas
Автор

Thank you :) I'll definitely cover JAX-RS in an upcoming tutorial. Thank you for the request. I've been holding off on Java networking stuff, but I'll cover it completely soon

derekbanas
Автор

I came across your tutorials on youtube and I feel blessed that I have found you. Your tutorials are so helpful. God bless you!! Keep up the good work!! Please make some tutorials on Java Concurrency.

nehaagrawal
Автор

Thank you Derek for all your enthusiasm to put it together in a better way...
We appreciate your hard work and your support. You Rock!!

I just found your tutorials yesterday and been love with your website.. Great job!!

shibaramsahoo
Автор

Thump up man, your design pattern codes example was really really useful. Its 100% understandable than a reading a lot of books without really see how the design should be. Many Thanks for your dedication.

javaidbolaky
Автор

Thank you :) I greatly appreciate the compliments. I'll try to live up to them. I'm getting very close to doing something very good. I can't wait to cover both games and the math behind them while at the same time cover electronics on a deep level. This is very fun for me.

derekbanas
Автор

Thank you :) Yes, I'll cover Android as soon as I'm done with design patterns. Believe me the work you do here will make making android apps extremely easy

derekbanas
Автор

Great one..The intention of Singleton pattern is very well fulfilled.But one thing I would like to suggest is that in multi-threaded environment we need to make the instance variable volatile. Making it volatile will prevent the re-ordering of the instructions and thereby avoiding undesired behavior.

sambitkabi
Автор

Thank you :) It is great to hear that I cleared everything up. That is the best compliment I could get.

derekbanas
Автор

Love your tutorials, they are quick and concise, and to the point. Excellent!

LauraHLY
Автор

Thank you :) I used them as one source, but also a bunch of others as well as friends for this. I'm glad it helped

derekbanas
Автор

Can you be my professor? The world needs more people like you!

stepho
Автор

Thank you very much :) I'm glad you found them useful. I will definitely cover enterprise design patterns, but I haven't covered JEE yet. I decided to make a truly complete java tutorial. i never figured it would take me 2 years to do it. At this rate I'll be making them for another 2 years since Android joined the tutorial.

derekbanas
Автор

The whole series on design patterns from you is awesome - thank you very much for your efforts on that!
However in my opinion I think they would be twice as awesome if you would simply slow down - say about half the speed. No need to change anything else since the content is already great. Just give us 3 or 4 seconds every time you would otherwise flip to the next screen.
For now I'm constantly doing play/pause and my mouse may quit service soon ;-)

heikomeyer