Kotlin Singleton Tutorial - Companion Object, Operator Invoke

Поділитися
Вставка
  • Опубліковано 8 лип 2024
  • 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.
    👉 bit.ly/3lMLtpj
    All the codes about this Kotlin Android Tutorial for Beginners are organized sequentially in this repository
    👉 bit.ly/2UoyiQf
    And if you need more support, then you can join the Simplified Coding’s Quora Space to post your questions.
    👉 www.quora.com/q/simplifiedcoding
    If you want to get in touch with me; you can find my contact details here:
    👉 www.simplifiedcoding.net/about/
    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.
    👉 www.simplifiedcoding.net
    You can SUPPORT me if you want
    👉 Patreon: / belalkhan
    👉 UPI (India Only): probelalkhan@okaxis
    👉 PayTM (India Only): +917549161079
    👉 PayPal: www.paypal.me/probelalkhan
    You can also check some of my other courses from these links
    👉 Android MVVM Tutorial: bit.ly/3iLfVzu
    👉 Android Game Development Tutorial: bit.ly/38JmltC
    👉 Retrofit Android Tutorial: bit.ly/2DEwAl1
    👉 Android RecyclerView Tutorial: bit.ly/2TqVjPz
    👉 Android Room Tutorial: bit.ly/2PfQHeN
    👉 Firebase Auth Tutorial: bit.ly/2WUGhEo
    👉 Android Notification Tutorial: bit.ly/2Sc6jQl
    👉 Building a Complete Wallpaper App: bit.ly/30UN8zV
    👉 Build Tic Tac Toe in Android: bit.ly/30goxW0
    ❤️❤️ Thank You All for the Love and Support ❤️❤️
    #KotlinOOP
    #OOPsConcept
    #LearnKotlin
  • Наука та технологія

КОМЕНТАРІ • 33

  • @gibraanjafar1669
    @gibraanjafar1669 3 роки тому +1

    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

  • @gulfappdeveloper2849
    @gulfappdeveloper2849 3 роки тому +5

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

  • @shreyashchoudhary7413
    @shreyashchoudhary7413 3 роки тому +1

    Loved it!

  • @deeprajpandey7612
    @deeprajpandey7612 3 роки тому +2

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

  • @zakariarada1856
    @zakariarada1856 3 роки тому +1

    GREAT THANKS, BRO.

  • @trunghieu5386
    @trunghieu5386 3 роки тому +1

    you saved my day

  • @tuyenvokhac7943
    @tuyenvokhac7943 3 роки тому +1

    Perfect explanation

  • @benjaminsilva7384
    @benjaminsilva7384 2 роки тому

    The best video of world

  • @Affliction604
    @Affliction604 3 роки тому

    Thank you

  • @deepakshah3108
    @deepakshah3108 Рік тому

    Super explanation

  • @peshutanpavri1599
    @peshutanpavri1599 2 роки тому

    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 :)

  • @tortoiseshell_cat
    @tortoiseshell_cat 3 роки тому +1

    Gold❤️

  • @hanki009
    @hanki009 3 роки тому +2

    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?

  • @akashviet007
    @akashviet007 3 роки тому +1

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

  • @Sojee19
    @Sojee19 2 роки тому

    Thanku thanku thanku thanku thanku

  • @youmeandeveryone5893
    @youmeandeveryone5893 3 роки тому +3

    Who else liking Kotlin more than Java?😀

  • @muskanyousaf20
    @muskanyousaf20 3 роки тому +1

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

  • @amazoncrazydeals5061
    @amazoncrazydeals5061 3 роки тому +1

    Great

  • @veedfriendforever5990
    @veedfriendforever5990 3 роки тому +1

    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

  • @mohamedfiyaz8356
    @mohamedfiyaz8356 3 роки тому +1

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

  • @RWS123ful
    @RWS123ful 5 місяців тому

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

  • @indra.ndra26
    @indra.ndra26 3 роки тому +1

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

    • @SimplifiedCoding
      @SimplifiedCoding  3 роки тому +1

      You can use operator fun invoke, or you can use companion object way as I shown you initially.
      Or you can directly access object to assign objects that are needed.
      There are many ways, it depends on your use case.

  • @tortoiseshell_cat
    @tortoiseshell_cat 3 роки тому +1

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

    • @Sumitmaurya070
      @Sumitmaurya070 3 роки тому

      ur choice

    • @tortoiseshell_cat
      @tortoiseshell_cat 3 роки тому +1

      @@Sumitmaurya070 no getter in kotlin is better performance i read kotlin doca

    • @tortoiseshell_cat
      @tortoiseshell_cat 3 роки тому +1

      @@Sumitmaurya070 no getter in kotlin is better performance i read kotlin doca

  • @tortoiseshell_cat
    @tortoiseshell_cat 3 роки тому +2

    Mann thanksssss i wish i can put 2 like

    • @deeprajpandey7612
      @deeprajpandey7612 3 роки тому +1

      bhai jab wish kar hi rahe ho to 2 se jayada hi ka wish kar lo....:)

    • @tortoiseshell_cat
      @tortoiseshell_cat 3 роки тому

      @@deeprajpandey7612 ????

    • @deeprajpandey7612
      @deeprajpandey7612 3 роки тому

      @@tortoiseshell_cat its a joke bro.... haaaa....jab wish hi karna hai to kitna bhi like karna ka maan lete hai na... ha.aaaaa

    • @tortoiseshell_cat
      @tortoiseshell_cat 3 роки тому

      @@deeprajpandey7612 no hindi😀

    • @deeprajpandey7612
      @deeprajpandey7612 3 роки тому +1

      @@tortoiseshell_cat jokes a part bro... :)