Kotlin Delegating Properties Tutorial with Example

Поділитися
Вставка
  • Опубліковано 23 лип 2024
  • In last video we learned about Delegation Pattern, and how Kotlin supports it natively. We learned about Delegation with the help of interfaces.
    But the same concept of delegating responsibility to other objects can be applied with properties as well. And in this video we will learn how we can delegate class members using Kotlin Delegation.
    0:00 Introduction
    0:30 Why Property Delegation?
    2:38 Creating Delegate
    6:15 Delegating Properties
    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

  • @RCMOULI1
    @RCMOULI1 2 роки тому +12

    Kind of confusing syntax but explained well. Programming is getting crazy over the decades.

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

    Finally, I understand delegation. THANKS ALOT.

  • @this-is-bioman
    @this-is-bioman 2 роки тому +1

    Excellent! I finally get the idea and I love this feature ;-D

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

    Amazing explanation. I never thought how easy it is.

  • @ss-xn5rw
    @ss-xn5rw 3 роки тому

    you explained this very beautifully

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

    Thanks a lot, such a clear explanation

  • @-untilwearrive4701
    @-untilwearrive4701 Рік тому

    Best explanation, thanks a lot

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

    Excellent example, regards from Caracas, Venezuela

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

    Loved it!

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

    Hi
    Have one doubt
    I try to re assign some different value (which is below range of 5) in student's firstName and lastName but it cannot assign again
    In output, it shows old value

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

    you have explained very well

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

    Thank you Sir

  • @28Saransh
    @28Saransh 3 роки тому

    thanks man!

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

    Hi belal... Can you please make just one more video on reflection in kotlin and add it to this list,,,, I need to fully understand Reflection,, you are amazing teacher thank you

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

    is NameDelegate object created for each property or there is only one object for every property. Because if it create objects for each property then it may be inefficient.

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

    Can't we achieve the same with extension functions ?

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

    How I want check varriavble value is even only using a single variable not a class

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

    confusing with operator fun , by the way great info

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

      Custom implementation of the 'setValue' operator using operator overloading.

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

    Hey Belal. How is this delegation any different than creating a common private method to avoid redundant code? I mean what is the significance of delegation over creating a common method in this case?

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

    Viradar you threw Kproperty and operator keyword without explaining, I finding it difficult to follow this way

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

    I didn't understand the property thing please someone explain

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

    Hi sir , how to crack technical round android interviews 😢
    Suppose if they ask either API calling or something like that?? I am new...

    • @ss-xn5rw
      @ss-xn5rw 3 роки тому +1

      you can say i am fresher and learning these topics or better to learn these topics in this channel.

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

      @@ss-xn5rw thank you...😊😊

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

    Okay I understand delegation, but what would be called as delegate in the above example?

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

      It is delegation in the sense that you are sending validation responsibility to another class that actually validating the first and last name.

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

    cant we just create a function that does the validation and used that validation in setter and getter like this
    class Student {
    var firstName: String? = null
    set(value) {
    if (isValid(value))
    field = value?.trim()?.toUpperCase()
    }
    var secondName: String? = null
    set(value) {
    if (isValid(value))
    field = value?.trim()?.toUpperCase()
    }
    private fun isValid(data: String?) = data != null && data.length > 5
    }

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

      Still the delegation is more concise as you can clearly see.

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

    This can be done easily by using Extension functions.

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

    Good content

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

    a