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 - Наука та технологія
Kind of confusing syntax but explained well. Programming is getting crazy over the decades.
Finally, I understand delegation. THANKS ALOT.
Excellent! I finally get the idea and I love this feature ;-D
Amazing explanation. I never thought how easy it is.
you explained this very beautifully
Thanks a lot, such a clear explanation
Best explanation, thanks a lot
Excellent example, regards from Caracas, Venezuela
Loved it!
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
you have explained very well
Thank you Sir
thanks man!
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
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.
Can't we achieve the same with extension functions ?
How I want check varriavble value is even only using a single variable not a class
confusing with operator fun , by the way great info
Custom implementation of the 'setValue' operator using operator overloading.
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?
Can you submit your version of the code?
Viradar you threw Kproperty and operator keyword without explaining, I finding it difficult to follow this way
I didn't understand the property thing please someone explain
Hi sir , how to crack technical round android interviews 😢
Suppose if they ask either API calling or something like that?? I am new...
you can say i am fresher and learning these topics or better to learn these topics in this channel.
@@ss-xn5rw thank you...😊😊
Okay I understand delegation, but what would be called as delegate in the above example?
It is delegation in the sense that you are sending validation responsibility to another class that actually validating the first and last name.
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
}
Still the delegation is more concise as you can clearly see.
This can be done easily by using Extension functions.
Good content
a