How to use Factory Method Design Pattern to design a course website like Udacity, Edx, Coursera...

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ม.ค. 2025

ความคิดเห็น • 82

  • @techforpeace38183
    @techforpeace38183 ปีที่แล้ว +5

    The best playlist on Design Patterns I have seen so far. Your way of explanation, examples, animations everything is top notch. Thanks a million to you.

  • @curiossoul
    @curiossoul 2 ปีที่แล้ว +17

    I presented similar design in one of the tech interviews and was questioned on breaking OCP in factory class.
    Though this is mostly taught by most authors for explaining the concept, in reality, we can avoid switch case with map so factory method just look up the map and return the value. Now to build the map, we have two choices
    1. Provide register product method in factory so product can register itself and then can be returned
    2. Use reflection to load classes in a map at startup. Map is maintained by factory class. Map key is identifier used in switch case and value is return type of factory method.

    • @sudocode
      @sudocode  2 ปีที่แล้ว +2

      Both ways are good enough as an alternate to switch case. At the end factory does have knowledge of the map or the way to figure out the concrete class.

    • @curiossoul
      @curiossoul 2 ปีที่แล้ว +1

      @@sudocode if you agree, would you consider editing the video or add a top level comment to let readers know about this. It might save them from getting kicked out from their dream jobs at no fault of theirs.

    • @sandeepchebrolu3129
      @sandeepchebrolu3129 2 ปีที่แล้ว

      Any sample code for for not vloilating OCP, please share.

    • @chippapruthvi2773
      @chippapruthvi2773 2 ปีที่แล้ว +2

      We use map in our project

    • @sureshiva4605
      @sureshiva4605 ปีที่แล้ว

      I was about to say OCP....You pointed out

  • @mireazma
    @mireazma ปีที่แล้ว +3

    9:51 CreateCourse() is not the meat and potatoes of the Factory pattern. The Factory pattern relies on delegating the object creation to a class specialized for this purpose. The underlying mechanisms of the actual creation vary by use case and are beyond the scope of the Factory pattern.

  • @lapimpale
    @lapimpale 2 ปีที่แล้ว +8

    The second example was little bit complicated but I really like createVehicle example. Thank you for explaining in easy manner.

    • @sudocode
      @sudocode  2 ปีที่แล้ว

      Do you mean the factory example was complicated or the coding example ?

    • @lapimpale
      @lapimpale 2 ปีที่แล้ว +1

      @@sudocode the course module example. I am at intermediate level may be it’s easy to understand for someone who knows better than me

  • @mireazma
    @mireazma ปีที่แล้ว +2

    1. 2:28 the class that implements the creation logic is wrongfully called "concrete" class, or subclass, that implement the factory method interface. The "factory" class need not be an abstraction for the creation implemention but a totally separated class. This is because you want to decouple the objects being created, from the factory (see 5.).
    2. 2:56 the same thing. You say that the FactoryClass is abstract or an interface.
    3. 4:40 the concrete class is _not_ hidden from the interface that it implements, it just can't be. But it is hidden from the client.
    4. 9:51 In the Course example you make the Course class abstract. Furthermore you have an abstract method named createCourse() which would suggest it's responsible for the underlying logic of a factory method like newing the Course. In fact it has to do with inner composition of a Course but not with its instantiation.
    5. You made the CourseFactory not an abstract class/interface and well you did. But remember what you said in 1. and 2. But you name the instantiating code getCourse() which would suggest it returns a permanent unique field of the class. You should name _this_ createCourse() or just create().

  • @sarinkumarpatle660
    @sarinkumarpatle660 ปีที่แล้ว

    Before coming to this tutorial, I am having, doubts about design pattern but the way explained all the things it is easy to understand.
    Thank you very much for such informative video ☺

  • @shabanaasmi2807
    @shabanaasmi2807 ปีที่แล้ว

    Very well explained, have been searching for the videos and got this. You saved my life. Thank you ❤

  • @manishperiwal515
    @manishperiwal515 2 ปีที่แล้ว +3

    Great example. If you can also explain the code flow through debugger, that will help to understand code much better.

  • @gilbert.gabriel
    @gilbert.gabriel ปีที่แล้ว

    This is an amazing video. Thank you for the wonderful explanation. First time I understood what Factory method pattern is actually meant for.

  • @srivatsa1193
    @srivatsa1193 ปีที่แล้ว +1

    You are amazing! Thanks for creating HLD, LLD, and Design patterns courses.

  • @ganeshkhirwadkar4127
    @ganeshkhirwadkar4127 2 ปีที่แล้ว

    Bahut kam log samjha pate hai is tarah ! Aap unme se ek hai. Thanks for this explaination, I was wondering why this series is not resumed , Hoping you will continue and we will get best out of this series !

    • @sudocode
      @sudocode  2 ปีที่แล้ว

      Thanks. Check the community posts and you will know why the delays in series 😊

    • @ganeshkhirwadkar4127
      @ganeshkhirwadkar4127 2 ปีที่แล้ว

      @@sudocode Pakka

  • @gokulsrinivasan8563
    @gokulsrinivasan8563 10 หลายเดือนก่อน

    I really love your video editing work 😍

  • @ronitnath3786
    @ronitnath3786 2 ปีที่แล้ว +1

    Excellent explanation. Could you please add video for decorator design pattern?

  • @sanjayyadav-tw8mt
    @sanjayyadav-tw8mt 2 ปีที่แล้ว

    Crystal Clear Explanation. Thanks!

  • @felipekobra
    @felipekobra ปีที่แล้ว

    Nmrl parça, finalmente consegui entender o bgl, tmj

  • @Dinesh8426
    @Dinesh8426 2 ปีที่แล้ว

    Supreb expiation ❤️👌👌
    You always made easy 😊

  • @pauladityashaw4590
    @pauladityashaw4590 2 ปีที่แล้ว +2

    What is the program you use to create class diagrams???

  • @bollywood90ssongs65
    @bollywood90ssongs65 2 หลายเดือนก่อน

    does it corelate to open / close principle. if one of the new requirement there will be modification , any alternative for this ?

  • @nitin4598
    @nitin4598 2 ปีที่แล้ว +2

    Useful information, but maam dnt you think swich is violating OCP in case we have to add new type.. If not then can you please explain??

    • @curiossoul
      @curiossoul ปีที่แล้ว

      Use map instead of switch here, load this map from properties file on startup

  • @ankurcharan
    @ankurcharan 2 ปีที่แล้ว

    Great video, yogita.
    btw, do you have someone for your video editing or how do you do it?

  • @jasper5016
    @jasper5016 ปีที่แล้ว

    Hi Arpita, can you please take more use cases for Low-level design eg. Parking lot, School Management Systems, Hospital Management System, etc?

  • @jagmohangautam1062
    @jagmohangautam1062 2 หลายเดือนก่อน

    In which of the scenarios would you use factory pattern and why?
    Consuming a service
    Complex Validation
    Logging
    Data Binding
    None of the Above

  • @SaiSumanthKovuru
    @SaiSumanthKovuru 10 หลายเดือนก่อน +1

    Where can we find the code that was explained in the video ?

  • @saumitrasaxena8470
    @saumitrasaxena8470 2 ปีที่แล้ว +2

    Hi Yogita Maam , At 4:15 you showed in diagram that Factory Class contains no implementation .That is not the case as in factory class,factory method should contain the logic to determine one of the concrete class.In the slide you showed , logic to detremine which subclass is resposibility of subclass but thats not the case as logic to determine which concrete class is the responsibility of Factory class . Could you please clarify on this ?
    package com.journaldev.design.factory;
    import com.journaldev.design.model.Computer;
    import com.journaldev.design.model.PC;
    import com.journaldev.design.model.Server;
    public class ComputerFactory {
    public static Computer getComputer(String type, String ram, String hdd, String cpu){
    if("PC".equalsIgnoreCase(type)) return new PC(ram, hdd, cpu);
    else if("Server".equalsIgnoreCase(type)) return new Server(ram, hdd, cpu);

    return null;
    }
    }

    • @sudocode
      @sudocode  2 ปีที่แล้ว

      It means no implementation to initialise the actual object creation :)

    • @saumitrasaxena8470
      @saumitrasaxena8470 2 ปีที่แล้ว

      @@sudocode Yes .But thta's not correct.Initialization to create actual object is always done in factory class.see below code 2 code from geekfor fees and journaldev .
      public class NotificationFactory {
      public static Notification createNotification(String channel)
      {
      if (channel == null || channel.isEmpty())
      return null;
      switch (channel) {
      case "SMS":
      return new SMSNotification();
      case "EMAIL":
      return new EmailNotification();
      case "PUSH":
      return new PushNotification();
      default:
      throw new IllegalArgumentException("Unknown channel "+channel);
      }
      }
      }
      public class ComputerFactory {
      public static Computer getComputer(String type, String ram, String hdd, String cpu){
      if("PC".equalsIgnoreCase(type)) return new PC(ram, hdd, cpu);
      else if("Server".equalsIgnoreCase(type)) return new Server(ram, hdd, cpu);

      return null;
      }
      }

    • @gaurika4927
      @gaurika4927 2 ปีที่แล้ว

      I agree with Saumitra Saxena. In your example also CourseFactory has logic to initialize object of concrete class like HLD, LLD and not the concrete class has that switch case logic. This is done to ensure only Factory class is open for changes and rest are closed for modifications.

  • @manavalanmichael8517
    @manavalanmichael8517 2 ปีที่แล้ว

    The Content is impressive, presentations. Which software used to create this content?

  • @venkatah9847
    @venkatah9847 2 ปีที่แล้ว

    Thank you for the video on an import pattern 👍

  • @mocococo2877
    @mocococo2877 2 ปีที่แล้ว

    Hello and geetings from Bulgaria.
    I like your energetic and well explained courses. However ...
    I can see for last ... many years that it is the Indian scholars pushing the abstract methods while many other have given them up. For ex. the whole C# platform is based on the implementation of interfaces. Which in OOP terms gives us the "is a" relationships. Down the line that also help to implement the very modern now concepts like dependency injection and automatic unit tests. In both cases we can inject an object as another object's "has a", as well as we can inject a Mock object with pre-setup return values. That is for as long as those objects implement the desired interfaces.
    I would love to engage you on small chat / discussion about that.
    Thank you,
    ILIIA

    • @sudocode
      @sudocode  2 ปีที่แล้ว

      Thank you for your comments. I would have loved to chat with you if you haven’t opened with the Indian scholars. Computer science is a science. It has nothing to do with origin of the scientists. Wish you well 😊

    • @mocococo2877
      @mocococo2877 2 ปีที่แล้ว

      @@sudocode Word scholars is a valid word and it has a meaning within any science regardless how precise science is.
      If one looks for insult he or she will inevitably find it.
      Wish you well

  • @mateuszmoscicki308
    @mateuszmoscicki308 2 ปีที่แล้ว +1

    Hello. I appreciate your effort. I have a question regarding the switch statement in your CourseFactory class as well as else-if statements in the vehicles example. Aren't those breaking the open-closed principle?

    • @sudocode
      @sudocode  2 ปีที่แล้ว

      No they are not. They are open for extension in a sense you can add more courses but they are closed because each course has its own createCourse method which you cannot modify :)

    • @mateuszmoscicki308
      @mateuszmoscicki308 2 ปีที่แล้ว +1

      @@sudocode what if I want to extend your app by creating another type of course? Will I have to modify your class?

    • @treyawey3878
      @treyawey3878 2 ปีที่แล้ว

      I think we cannot strictly follow each of the principles. They are subjective and we need to think based on what is easier and feasible for the given scenario.

  • @manishkumarprajapati6280
    @manishkumarprajapati6280 หลายเดือนก่อน

    Wait ! Whats that VS Code extension for generating class diagram

  • @akjoker79
    @akjoker79 3 หลายเดือนก่อน

    This is simple factory. The factory method pattern by GOF will have subclasses create the instances

  • @saiprasadkyatam1702
    @saiprasadkyatam1702 ปีที่แล้ว

    If i create multiple concreate class based on vehicle type (TruckCreator, CarCreator, PlaneCreator) than based on type of vehicle if i return the creator class then that factory interface isnt working like facade class? please answer

  • @dibyaprakashpandey7857
    @dibyaprakashpandey7857 2 ปีที่แล้ว

    Excellent 👌👍

  • @UditSharma124
    @UditSharma124 ปีที่แล้ว

    Can we have example of strategy DP too?

  • @amritprakash4264
    @amritprakash4264 9 หลายเดือนก่อน

    where can i get the slides or animation doc used in the course??

  • @sanketh768
    @sanketh768 ปีที่แล้ว

    Hello mam, it looks like you're using premium features of IntelliJ , is it provided by your company or you bought the license on your own ?

    • @sudocode
      @sudocode  ปีที่แล้ว

      I have my own license

  • @mdnadeemasgar6279
    @mdnadeemasgar6279 ปีที่แล้ว

    Hi Yogita, can you please upload the code online and share the code url in the description. So that we can also try manipulating the code for the given design pattern.

  • @108vicky
    @108vicky ปีที่แล้ว

    Nice explained

  • @prataptyagi5082
    @prataptyagi5082 ปีที่แล้ว

    Doubt:-
    Is it the same method that's used to expose transaction API's of any bank to Amazon kind of 3rd party

  • @keshavmaheshwari521
    @keshavmaheshwari521 27 วันที่ผ่านมา

    what about abstract factory pattern?

  • @divyangdesai1634
    @divyangdesai1634 10 หลายเดือนก่อน

    Q: What if LLD and HLD class would have different constructor dependencies?

  • @savita6670
    @savita6670 2 ปีที่แล้ว

    After long time

  • @AbhishekYadav-fb3uh
    @AbhishekYadav-fb3uh 2 ปีที่แล้ว

    thanks for such video

  • @koteshwarraomaripudi1080
    @koteshwarraomaripudi1080 2 ปีที่แล้ว

    You have not used createCourse method in factory method to create instance instead used new Class() directly.

  • @zeeshan4989
    @zeeshan4989 2 ปีที่แล้ว

    As always on to the point and easy to understand . waiting for another design pattern video.
    I have one off the topic query . how is your experience on LinkedIn Learning? dose it actually add some extra point when it comes to big companies ?I would really appreciate your response. Thanks !

  • @saravanakumarradhakrishnan756
    @saravanakumarradhakrishnan756 ปีที่แล้ว +4

    This is simple factory only. Not a factory pattern.

    • @sivaprasad6621
      @sivaprasad6621 6 หลายเดือนก่อน

      Yes. I was looking for this comment.

    • @NidhishAbraham
      @NidhishAbraham 11 วันที่ผ่านมา +1

      𝗦𝗶𝗺𝗽𝗹𝗲 𝗙𝗮𝗰𝘁𝗼𝗿𝘆: A class with a single method that creates objects of different types based on provided input.
      Not a "true" Design Pattern: Often considered an implementation technique rather than a formal design pattern.
      𝗙𝗮𝗰𝘁𝗼𝗿𝘆 𝗣𝗮𝘁𝘁𝗲𝗿𝗻 (𝗔𝗯𝘀𝘁𝗿𝗮𝗰𝘁 𝗙𝗮𝗰𝘁𝗼𝗿𝘆): A design pattern that provides an interface for creating families of related or dependent objects without specifying their concrete classes.
      Delegates the responsibility of instantiation to a subclass or an interface, adhering to the Open-Closed Principle (OCP).

  • @khushboopriya9895
    @khushboopriya9895 2 ปีที่แล้ว

    Where can I find the code?

  • @AdityaKumar-iy8vl
    @AdityaKumar-iy8vl 6 หลายเดือนก่อน

    Can I get the source code please?

  • @jimbo0o
    @jimbo0o 2 หลายเดือนก่อน

    👏👏👏👏👏

  • @itzak0422
    @itzak0422 2 ปีที่แล้ว

    I am bca first year student . Can i become a software engineer? Plz tell me roadmap.

    • @premmahto4855
      @premmahto4855 2 ปีที่แล้ว +1

      ofcourse

    • @premmahto4855
      @premmahto4855 2 ปีที่แล้ว +1

      just search a good programming language that is in demand and has a future.
      Apart from programming there is a lot career choice in IT, Qa( software testing) , network security , DBA etc

  • @CodingJoySoul
    @CodingJoySoul ปีที่แล้ว

    Why have you stopped making videos. You don't how popular are your videos amongst students

    • @sudocode
      @sudocode  ปีที่แล้ว

      I will be making more. Just took a short break.

  • @nathamuni9435
    @nathamuni9435 2 ปีที่แล้ว

    KINDLY SHARE THIS FACTORY METHOD PACKAGE THAT U HAVE IMPLEMENTED

  • @arupde6320
    @arupde6320 2 ปีที่แล้ว

    complete the playlist quickly

  • @chandlerbing8164
    @chandlerbing8164 11 หลายเดือนก่อน

    i think that code is completly wrong
    theory was right but the implementation was very poor

  • @NaturalHabitat52
    @NaturalHabitat52 ปีที่แล้ว

  • @ChandraTech52
    @ChandraTech52 2 ปีที่แล้ว