You've missed a client isolation implemanaton which would isolate from growing list of your Branch classes. You should have something like Branches class which would compound of all branches, Basically O/C Principle.
your explanation is very helpful , but I think there is still chances of being the OCP violation. because, in the future we can add ApplePay, VisaCardPay, MastercardPay etc type of payment methods. then we will have to rewrite our enum (basically we will have to add new options in the PaymentMethod enum) and we will have to add more options in the "switch case" PaymentFactory.create method. in this case we can use the help of reflection. so, we won't have to add any more new options to any enum or swith case. Please correct me if I am wrong. I will be delighted to know my mistakes. Thanks a lot for you video. I hope and pray for your wellbeing.
This only video resumed more than 6 hours in-person classes and three times more hours of study. At almost 50 my head is not that fast to understand these concepts, so thank you very much for this priceless piece!
Great video! The music and your commentary are very relaxing. You might be interested in my library, M31.FluentAPI, for generating builders via Roslyn source code generation. Keep up the great work!
I've read that a global variable in python, natively behaves like a singleton, for instance like all the modules once imported, they don't make a difference when trying to re-import. Could you also touch base on that approach and hopefully explain us viewers pls. thanks in advance.
Great video! I was watching one of your other videos explaining abstract factory methods in C#, but halfway through it was marked as private, so I didn't get to see the rest. Will it come back up?
A perfect example of the meaningful application of the Factory Design Pattern. I have seen dozens of videos. This is the only one that clearly shows the benefits of the Factory Pattern.
Best tutorial I have seen on this subject. The example classes were much easier to follow and therefor understand without 'abstract' examples such as foo / bar - thank you!
what if you have huge data like 100000000comments in Post object. I don't think you can init a domain object with that much... looks useless to me when dealing with large chunks of data. Thoughts?
Like this right ? IInternationalFactory internationalFactory = InternationalProvider.CreateCountry(Country.England); ILanguage language = internationalFactory.CreateLanguage(); ICapitalCity capitalCity = internationalFactory.CreateCapitalCity();
Not that it matters too much, since Python is a dynamically typed language. I'm not even sure if a tool like mypy would even catch this. But in 4:15 you want to specify the actual "type" of the method's return type, and not an instance of the expected type: @abstractmethod def list_top_attraction(self) -> list[str]: ...
Hello sir, would like to ask a question regarding the code in the GitHub repository. In the product class (email_message.py) I see that youve placed a setter method for 'to', which is def set_to. But in the video and the repository, the builder class makes use of the get_to method to get the argument passed to provide the value for 'to'. I may have overlooked it on my part, but I dont see the set_to method being used and I'm kind of confused regarding its purpose. I'd just kindly like to know where the set_to method is being used. Thank you very much!
Hello Coach, Hope this message finds you well. I'm reaching out to you today because I believe your courses have the potential to attract a significant number of students and generate positive reviews. Would you be interested in proceeding further? Here are my marketing plan to promote your Udemy course to attract more students and gain many positive 5 stars reviews: 1. Offering free Coupon: Provide a taste of your course content with a free coupon to enroll 1000 students in 5 days. 2. Utilizing Social Media 3. Email Marketing Campaign 4. And possibly running ads. I am looking forward to hearing from you soon.
@@campbelltech Hello coach, There are several benefits in promoting your courses and getting positive reviews . Firstly, having thousands of students enrolled in your courses can significantly increase your visibility on the platform, making it easier for new students to discover and enroll in your courses. Additionally, positive 5-star reviews can help establish your credibility as an instructor and encourage more students to enroll in your courses. On the other hand, not having thousands of students and many positive reviews can have some disadvantages. For example, your courses may not be as visible to potential students, making it harder to attract new enrollments. Additionally, having fewer reviews, especially if they are not positive, can make it harder to establish credibility and trust with potential students. Overall, while there are some challenges and disadvantages to consider, the benefits of reaching thousands of students and generating many positive reviews can greatly outweigh them. I look forward to your response, and please let me know if you have any questions on how you can get started.
Thanks for this video, it's very helpful! One question, however. Using the example at 19:00, what is the correct way to accept a parameter on line 7? We may need to accept "South" or "North" as parameters of SpainFactory constructor to make sure language changes from "Spanish" or "Catalan" respectively. Is there a better pattern for this or do we simply make custom constructors in SpainFactory?
Hi I’m learning design patterns I like your videos but can you possibly make a video of when I should maybe use factory method vs abstract. I understand there isn’t a simple answer but maybe a “Look for these signs answer”
The client code, however, remains unchanged and follows the open-closed principle. Many would argue that adding the enums and extending the factory method only, still remain within the boundaries of the open-closed principle. If you want to comply on all levels, you will have to use reflection, possibly compromising on performance.
What do you do if CreditCard has a method GetStatement that returns a CreditCardStatementModel object, but GetStatement for paypal returns a PayPalStatementModel object with different fields? Since methods have the same name but a different return type, you couldn't implement a common interface.
Hi Kyle, you can introduce a base or abstract StatementModel. Then CreditCardStatementModel and PayPalStatementModel can inherit from or extend StatementModel. Then, let the GetStatement method return StatementModel, and through Polymorphism you can "cast" it back to the concrete types in the concrete classes.
In this case we can use abstract class instead of using an interface. which can have an abstract method named "Statement" which will return a statement. other classes like GooglePay, PayPal and CreditCard will override and implement the same "Statement" method but will return different statements. I hope, I explained it correctly.
What happens when I have to pass different parameters to each factory? What if my CreditCard needs additional parametets different from GooglePay or whatever
Good question. I would suggest using Polymorphism to overcome this challenge. In other words, have a single parameter that is of a complex object base type. Then you can have multiple concrete classes with the specific fields that you need that extend the base class. Then you can cast the base to the concrete class in your specific implementation (which the factory returns). I hope this makes sense?
Excellent thank you. Can you tell me what is the difference between this pattern and a Factory Pattern, and what is the advantage of using this pattern (in what context?). You have a very good logical way of explaining. Please do more videos on Python.
Thanks, JC! The main difference between the builder pattern and the factory pattern lies in their focus: Fluent builder pattern: Helps construct complex objects step-by-step with optional configurations. It acts like a "recipe" where you choose the ingredients (object properties) and add them one by one. This enables flexible object creation with improved readability, especially for objects with many optional fields. Factory pattern: Deals with encapsulating object creation logic and choosing the right type of object to create based on certain criteria. It's like a switchboard that decides which "machine" (object) to turn on based on the input. This promotes loose coupling and simplifies object creation when choosing between different implementations. The advantages of using these patterns depend on the context: Use the fluent builder pattern when: - You have a complex object with many optional configurations. - You want to improve code readability and clarity for object creation. - You need a flexible way to define default values for optional fields. Use the factory pattern when: - You need to create different types of objects based on different conditions. - You want to decouple your code from the specific implementation details of object creation. - You want to centralize the logic for choosing the right object type.