Kotlin Companion Object & JVM Static | Kotlin Factory Pattern Tutorial | Cheezycode #27
Вставка
- Опубліковано 15 жов 2024
- In this tutorial, learn about companion object in kotlin and implement factory pattern in kotlin Programming language. Learn how to JVM static for Kotlin Java Interoperability with working examples. This tutorial is part #27 of Kotlin Programming For Beginners Series. Learn Object Oriented Programming in Kotlin. Everything is explained in Hindi. Brief topics covered -
1. What is companion in Kotlin?
2. Use of Companion Object in Kotlin with example
3. Implement Kotlin Factory Pattern
4. How to implement static methods in Kotlin
5. JVM Static in Kotlin for Java Interoperability Tutorial
6. Object Oriented Programming in Kotlin
Learn all this in Hindi (हिंदी में )
Kotlin Beginners Tutorial Series -
• Kotlin Beginner Tutori...
For more info - visit below link
www.cheezycode.com
We are social. Follow us at -
Facebook - / cheezycode
Twitter - / cheezycode
Very nicely explained concept of companion object from scratch. Great Work!! 👏👏
You explain this in the best manner. Good
superb explanation sir...background music is so energetic :)..sir please send background music link.
thx brother, your video really helped me to understand companion objects. Thanks again...
Which compiler did you use
Good afternoon sir
Sir can I use companion object in abstract class if yes then how to overcome the problem of creating an object every time
Try karke dekho...debug Karo clear hojayega
Awesome video
Nice explanation sir 👌
Thanks
Sir,how many videos are left to complete this series??
What happened?
@@CheezyCode Sir, kotin series kb tk complete ho jaige??
Or abhi kitni or videos aane vali h??
Abhi aayengi videos ispe kaafi
what's the use of private constructor?
sir in pizza example what is the benefit of return object ?we can also return string
Sir please also cover lambda, inline,sealed classes.
Yes...in queue
Functional programming - Higher order functions, closures etc
nice sir
Thanks Asif
sir in 1:32 why you not create the object of myclass ?
This is how companion work. Object keyword creates a single object and if we declare that with companion - that object gets added to your class name. So no need to create object of a class. Companion gets added to your Class name itself.
Similar to Static in Java but not exactly similar
@@CheezyCode
fun main() {
println(Sabji.Tamatar.description)
}
class Sabji {
object Tamatar {
var description = "Laal hai lelo"
}
}
-> If we are not using companion still there is no need to make object of a class right ?
I appreciate your effort and time but I think this is not an appropriate example of a factory pattern as you taught us factory pattern mean factory of objects but in this example, your focus is not on creating objects instead of just passing arguments to the constructor. Let me know if I'm not wrong.
Appreciated you asked this question. Factory pattern is way of creating objects. You tell them - Hey factory give me "A" object or give me "B" object. You need to tell factory that you need a particular type of object.
You need to tell the factory - what objects you need. For this thing - it could be XML file or may be some configuration or say some parameters is passed to factory. By looking at those values - factory decides - which object needs to be returned.
Here I have passed a parameter. Mainly pattern is about not instantiating object directly. In Kotlin it will be like val ob = A()
- we should not do something like this in our code. Hope it answers your query.
@@CheezyCode Yes, You answered very well. I'm learning kotlin from scratch to your videos these are very helpful and the way you deliver is impressive. I wish your all videos will get soon millions of views because you deserve it. Your efforts on video reflect your hard work on it. I'm suggesting your channel to my friends for kotlin.
This example is about to generate objects. I request you to kindly for the next core concept of the example should be reflected in the respective example thanks. Love from Pakistan
Hi, for the fun toString() we are not calling it so I guess in the main method where println() is called toString() is automatically called as it is present in the super class Any since we are not calling it explicitly?
println(any object) --> it explicitly calls its toString
thx @@CheezyCode
Kotlin scope function ko aap explain karo pls
Check the playlist section - full series is there
should remove bg music. It will help in concentratring
Removed in other videos...waise added to reduce other noises
Sir kotlin ko database se kaise connect krte hai
Jdbc same he hoga.... classes access kar skte ho
Java पढ़ने के बाद kotlin बिना सर पैर की लग रही है। केवल Java को replace करने के चक्कर में नई language खड़ी कर दी।
केवल Google vs Oracle टशन का नतीजा लग रहा है।
Even Dart is much better than Kotlin.
Well your way of explanation is excellent.
Java ki गहराई में उतर कर ही पता चलेगा की kotlin काफी बेहतरीन भाषा है।
@@CheezyCode I agree with you.
sir,
please one video dealy dalo
Bro koshish poori hoti h ... Video ke content pe mehnat kaafi lagti h...example ke liye kaafi mehnat jaati h..i hope you understand
@@CheezyCode awesome content
Mara ko C & Python aata ha aab mugha app development ma Jana ha ma Phala Java Karu Ya Kotlin
Bhaiya aap kotlin programming ka bad App Building Ka bhe videos Banana