Kotlin Singleton Tutorial - Companion Object, Operator Invoke

preview_player
Показать описание
In this Kotlin Singleton Tutorial, we will learn how easy it is to use Singleton Pattern in Kotlin. (Compared to other languages such as Java).

Singleton is an Object Oriented Design Pattern, and it is used when we want to have only a single instance of a class, that is shared throughout the application. It is often require, when the instance is frequently needed, so instead of creating the instance again and again, we can restrict it to just a single instance that will be shared throughout the application.

Kotlin makes, singleton very easy with zero boilerplate code. We just need to use the keyword object and the Singleton class is ready. Let's find out the whole step in this video.

0:00 What is Singleton?
0:42 Singleton the Old School Way
1:47 Companion Object
4:41 Invoke Operator
5:30 Problem with the Approach
5:54 Singleton, The Kotlin Way


If you are having difficulties navigating from one lesson to another, then click on this link and it will open the complete playlist of this Kotlin Object Oriented Programming. In this playlist all lessons are already arranged in chronological order.

All the codes about this Kotlin Android Tutorial for Beginners are organized sequentially in this repository

And if you need more support, then you can join the Simplified Coding’s Quora Space to post your questions.

If you want to get in touch with me; you can find my contact details here:

Finally, If you love my content please SHARE my courses to your friends. You can share this course to your Facebook, WhatsApp etc.

For more contents related to Software Development visit my website.

You can SUPPORT me if you want
👉 PayTM (India Only): +917549161079

You can also check some of my other courses from these links

❤️❤️ Thank You All for the Love and Support ❤️❤️

#KotlinOOP
#OOPsConcept
#LearnKotlin
Рекомендации по теме
Комментарии
Автор

Sir, you way of teaching is really superb.... keep making videos sir we really like your contents...

deeprajpandey
Автор

Thanks, it is usefull for retrofit & room database in android

gulfappdeveloper
Автор

I have learnt a lot from this playlist and I have subscribed, but I have to admit, I dont prefer Kotlin to Java anymore (at this time), maybe I will grow to like it :)

peshutanpavri
Автор

I don't understand the invoke operator, is it used with only companion block? or it has other uses also?

akashviet
Автор

What's the difference between creating object by singleton method and creating object by lazy delegates?

mohamedfiyaz
Автор

good morning,
Hello sir, I am working a project that require some permission that dose not provide normally so, want to know about device policy manager in describe details so please help if you?
thank you

veedfriendforever
Автор

Who else liking Kotlin more than Java?😀

youmeandeveryone
Автор

Only the initialization of an object declaration is thread-safe. If you are using this object outside it won't be thread-safe.

RWSful
Автор

Hi Belal, really insightful tutorial about Singleton. I would like to know how can we use the volatile keyword for our instance? Can we do that similar to java by adding volatile keyword ahead of the instance declaration?

hanki
Автор

Thnku For the Series 🤝 please make a Video on sockets with Api responses dealing please please🙏

muskanyousaf
Автор

Hi sir.. How to pass a parameter? in case we need the parameter to be passed to object class

indra.ndra
Автор

The content is so good, concise and to the point that I don't mind watching the adds. Thanks Belal for this really nice playlist

gibraanjafar
Автор

Can i user 'instance get()=...' instead of function and wich on is better

tortoiseshell_cat
join shbcf.ru