C++ Tutorial: the factory design pattern

Поділитися
Вставка
  • Опубліковано 17 гру 2024

КОМЕНТАРІ • 30

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

    Thanks! Great explanation!

  • @alexplaytop
    @alexplaytop 9 місяців тому +2

    Simply about hard stuff as for me, thank you very much!

  • @chandusrinivas7813
    @chandusrinivas7813 9 місяців тому +1

    Super explanation sir, Thank you!

  • @Muralikrishna-yz7jl
    @Muralikrishna-yz7jl Місяць тому

    Nicely explained.. Thank you very much

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

    Amazing video, thank you so much! This helped me prep for my C++ code design interview:)

    • @ProfessorHankStalica
      @ProfessorHankStalica  Рік тому +3

      Oh, that's fantastic! I hope you get the job. Good luck! If you get it, you owe me a beer! 🍻😆

  • @propov1802
    @propov1802 2 роки тому +2

    Excellent explanation.

  • @anjan8614
    @anjan8614 4 місяці тому

    Perfect sir. Thank you from INDIA. Subscribed to your channel.

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

    clear + simple = thank you so much

  • @RamvilasGurjar-g2o
    @RamvilasGurjar-g2o 10 місяців тому

    Hi Stalica, does the base class need virtual constructor in this method if there are other data also in the derived classes (Triangle, circle and square) ?

    • @ProfessorHankStalica
      @ProfessorHankStalica  10 місяців тому

      None of the classes need a virtual constructor.

    • @रामविलासगुर्जर-च9ङ
      @रामविलासगुर्जर-च9ङ 10 місяців тому

      ​@@ProfessorHankStalica sorry I was asking for virtual destructor

    • @ProfessorHankStalica
      @ProfessorHankStalica  10 місяців тому

      Never a bad idea to make destructors virtual so that way you guarantee the right destructor is executed for the right object if there is any chance for a class to be inherited from.

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

    Can this design pattern work for objects created on the stack rather than on the heap

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

      You could allocate the Factory object on the stack and use statically allocated memory to allocate instances of each object as attributes of the Factory. Then you could return any of them on demand. Something like that might work, but would be unusual.

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

    Can I simply think that the create() method is similar to the getClass() in Java, which in C++ returns a 'this' pointer?

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

    nice and clear video.
    which advantage do you see in using a Factory class instead of a create(type t) method directly (i.e. a factory method)?

    • @ProfessorHankStalica
      @ProfessorHankStalica  Рік тому +1

      If I understand the question, it's a matter of encapsulation and/or closely adhering to the object-oriented programming paradigm. Of course, rules can be broken, but it's going to depend on the requirements of your project and the overall resulting design you come up with. I prefer a consistent design, so if I'm going to do OOP, I'm going to do it all the way.

  • @alexfu1734
    @alexfu1734 10 місяців тому

    Why not using template instead of enum? Is factory required to support RTTI?

    • @ProfessorHankStalica
      @ProfessorHankStalica  10 місяців тому

      Just because. There's many ways you could implement a factory pattern. This is one.

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

    thank you so much

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

    Thank you