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

КОМЕНТАРІ • 44

  • @ashishjoshi6882
    @ashishjoshi6882 Рік тому +2

    Very nicely explained concept of companion object from scratch. Great Work!! 👏👏

  • @waqasahmed-u5o5w
    @waqasahmed-u5o5w Рік тому

    You explain this in the best manner. Good

  • @theroamersanjeev
    @theroamersanjeev 4 роки тому +3

    superb explanation sir...background music is so energetic :)..sir please send background music link.

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

    thx brother, your video really helped me to understand companion objects. Thanks again...

  • @BhagyashreeAware
    @BhagyashreeAware 3 місяці тому

    Which compiler did you use

  • @arpitkhandelwal2999
    @arpitkhandelwal2999 4 роки тому +3

    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

    • @CheezyCode
      @CheezyCode  4 роки тому +1

      Try karke dekho...debug Karo clear hojayega

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

    Awesome video

  • @amitpramanik260
    @amitpramanik260 4 роки тому +1

    Nice explanation sir 👌

  • @TheTechnobie
    @TheTechnobie 4 роки тому +1

    Sir,how many videos are left to complete this series??

    • @CheezyCode
      @CheezyCode  4 роки тому

      What happened?

    • @TheTechnobie
      @TheTechnobie 4 роки тому

      @@CheezyCode Sir, kotin series kb tk complete ho jaige??
      Or abhi kitni or videos aane vali h??

    • @CheezyCode
      @CheezyCode  4 роки тому +1

      Abhi aayengi videos ispe kaafi

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

    what's the use of private constructor?

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

    sir in pizza example what is the benefit of return object ?we can also return string

  • @LuckySingh-mx7tb
    @LuckySingh-mx7tb 4 роки тому +1

    Sir please also cover lambda, inline,sealed classes.

    • @CheezyCode
      @CheezyCode  4 роки тому

      Yes...in queue

    • @CheezyCode
      @CheezyCode  4 роки тому

      Functional programming - Higher order functions, closures etc

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

    nice sir

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

    sir in 1:32 why you not create the object of myclass ?

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

      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

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

      ​@@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 ?

  • @muhammadhamza7328
    @muhammadhamza7328 4 роки тому +1

    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.

    • @CheezyCode
      @CheezyCode  4 роки тому

      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.

    • @muhammadhamza7328
      @muhammadhamza7328 4 роки тому +4

      @@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

  • @rafsanshaikh2262
    @rafsanshaikh2262 2 роки тому +1

    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?

    • @CheezyCode
      @CheezyCode  2 роки тому +1

      println(any object) --> it explicitly calls its toString

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

      thx @@CheezyCode

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

    Kotlin scope function ko aap explain karo pls

    • @CheezyCode
      @CheezyCode  2 роки тому +1

      Check the playlist section - full series is there

  • @VaibhavBansal-l5r
    @VaibhavBansal-l5r Рік тому

    should remove bg music. It will help in concentratring

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

      Removed in other videos...waise added to reduce other noises

  • @GautamKumar-yv7li
    @GautamKumar-yv7li 4 роки тому

    Sir kotlin ko database se kaise connect krte hai

    • @CheezyCode
      @CheezyCode  4 роки тому

      Jdbc same he hoga.... classes access kar skte ho

  • @ajaykotiyal427
    @ajaykotiyal427 2 місяці тому

    Java पढ़ने के बाद kotlin बिना सर पैर की लग रही है। केवल Java को replace करने के चक्कर में नई language खड़ी कर दी।
    केवल Google vs Oracle टशन का नतीजा लग रहा है।
    Even Dart is much better than Kotlin.
    Well your way of explanation is excellent.

    • @CheezyCode
      @CheezyCode  2 місяці тому

      Java ki गहराई में उतर कर ही पता चलेगा की kotlin काफी बेहतरीन भाषा है।

    • @sadi404
      @sadi404 Місяць тому

      @@CheezyCode I agree with you.

  • @anantchoudhary3748
    @anantchoudhary3748 4 роки тому

    sir,
    please one video dealy dalo

    • @CheezyCode
      @CheezyCode  4 роки тому

      Bro koshish poori hoti h ... Video ke content pe mehnat kaafi lagti h...example ke liye kaafi mehnat jaati h..i hope you understand

    • @anantchoudhary3748
      @anantchoudhary3748 4 роки тому

      @@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