Hi, in this video we have covered #factoryPattern and #abstractFactoryPattern design patter out of many design pattern which is asked in Low level system design interview. ➡️ Become a Member: / @conceptandcoding
I am following your videos in LLD and HLD religiously. For not only any interview preparation, but to become a good engineer. Upade - finished this today.
And regarding abstract factory, although, you haven't coded it here, I just thought it is worth mentioning for the wider audience on the real use-case of that pattern. The example you showed is not the ideal use-case of the abstract factory. Luxury or ordinary, a car is still a car, so it should still be a factory. But, the most appropriate pattern for it is decorator, which prevents class explosion of different types of cars. Now coming to the real use-case of abstract factory. It has a very niche use-case, like some other behavioural patterns (e.g. flyweight). That use-case is creation of products in factory in a package. Imagine a racing game with different backgrounds, different landscapes, etc. you still need to create different unrelated objects, in same quantity, but with minor changes in the characteristics. That's where you use the abstract factory. For instance, one abstract factory will produce all the objects required in the game if it is played in rainy mountainous terrain, another abstract factory will create the same objects but in sunny desert terrain. The point is, when you create an object of sunny desert terrain, all the other objects of the game have to be created in sunny desert terrain, not rainy mountainous terrain. that's where the abstract factory really comes to the fore. so it is a bundled creation of objects based on criteria that drives whether you should use abstract factory or not.
These patterns were in my To-Do List since long. May be more than 2 years. But finally I was able to understand and completed the tasks successfully within two days. I really enjoyed the video. Looking forward for more videos like this. Thank you for your great efforts.
Studied the design pattern for the first time, but after studying it from your channel it felt like I have known these concepts for a long time. Amazing work bro...
Hello Shrayansh, Thanks for quality content. I am learning from your tutorials and also found this playlist one of the best. Recommending to my friends as well. Thanks
what you have described is a "SimpleFactory" . The creational pattern "factory method" pattern. Most get confused between the 2. in factory method pattern, In your super class you describe the work to be done using an abstraction. (coding to an interface) But someone has to create the real object. This creation is delegated to the sub class. The advantage is conformance to OCP. You create a new class which just creates the derived object which implements the abstraction.
Great video, because no one can explain in hindi in a simple way because in english there are tons of videos, but kuch samaj nahi aata unka and many indian FAANG are just making videos in english. pta nahi kya promote kr rahe hai. but acha hai LEARNING VIDEO should always be in hindi tabhi samajh aata hai bhale hi problem kitni bdi kyu na ho.
Help me understand it right. If we have a new Factory coming up as an economical luxury, is such a case, I would change the lower classes, right? For example, Hyundai should move from ordinary to econ. luxury. But that would be violating the SOLID principle classes not open to change. Any recommendation? Is there a way for concrete classes to select which factory they should belong to?
firstly thanks for doing this, really great stuff... secondly your examples help a lot.. can you please try giving more examples Sir.. I really wanted more abstract factory pattern examples.. helps in remembering
The first pattern is not Factory pattern. It is Simple Factory, which is more of a good programming practice. Also, In the class diagram, Shape "has a" Shape Factory to delegate responsibility of object creation to factory, but it is missing in the code implementation part. Also, please include Factory Method pattern.
One small correction: ShapeFactory interface doesn't have a "has-a" relationship with Shape interface. It doesn't hold a Shape object, instead, one of it's method creates and returns a shape object to the client based on some logic. Please correct me if I'm missing anything.
Great Explanation. Thanks for video. One Question, though: In many codebases i saw that developers use HashMap() instead of switch cases in factory function/method. Is this good practice or bad practice? Can you clarify ?
They are using that to remove switch or if conditions. From a collection they can manage. In dependency injections framework like ninject same way they are implementing i thought 🤔
Hi Shrayansh, You are doing a great job and the number of people like me get to learn the concepts in an easy way. However, in this video the factory pattern you explained is not the one from the gang of four factory patterns.please correct me if I mistaken.
Good content. Although, I just wanted to point out something so that other viewers are also aware of the nuance. This is a factory pattern, which is not really a design pattern, technically speaking. The actual pattern is factory method pattern, where the same over-ridden method will create different products.
i am not sure buddy, i can see yesterday also some engineers joined the membership. So its working fine. you can try udemy then. Link is in Channel about section
Great explanation. Though 1 thing I always struggle with is if factory needs to be an interface or abstract class. In one of the scalar masterclass It was said that behaviour difference => interface, attribute commons => abstract class. Is that correct?
@@HEMANTVERMA-pv2pe Ig yes, becoz it has different sub classes ( luxury and normal cars classes) under it And we want to return the factory obj assigned to those specific sub classes.. Not sure if I'm getting it right I'm assuming from the factory pattern at 5:26 , like he is assigning circle obj to Shape interface object ( he could assign square obj to Shape interface as well) , becoz both classes circle and square are implementing Shape interface
Hi Sir, just 1 doubt. What is the use of Abstract factory pattern. We could have use factory pattern itself for luxury and ordinary cars. What are the cons of using factory pattern in the scenario mentioned in the video??
Its nothing but a factory of factory. Whenever in your code you have multiple factory pattern and we want to pick which particular factory method to call, then this pattern can be used. To be honest. Factory pattern is very popularly used but Abstract Factory is very rarely used. But good to know this,
Shrayansh, will you please consider my one request? Sort the videos in the playlist in proper order. I'm watching this video and you mentioned that we have covered strategy and observer etc but in the playlist, they are below this video. So, I've not covered them all. It might be case for many. Just a suggestion. Thaks again for these insights. 🙂
Hi shreyansh, can you please provide code/github repo of given example of Abstract Factory pattern please ? I am trying to implement it but unable to do so.
this is the link, but abstract factory pattern code seems not there, will add it : gitlab.com/shrayansh8/interviewcodingpractise/-/tree/main/src/LowLevelDesign
Strategy pattern is a behavioral design pattern which is basically used to interchangibly use only one algorithm using polymorphism based on the object need where as factory is a creational design pattern that delegates object creation process to other class seperating out the dependent class and its actual dependacy (object of another class that it needs)
Please provide real example github code links as well. Understanding these patterns are easy but we need to see how they where implemented in real code. Some ref github repo should be enough
you have not explained abstract factory design properly, you should make another video for the same , also one suggestion , try to extend example of factory design pattern only for abstract factory , that will help students more to clearly understand the difference between the two
Few initial videos are in Hindi, but I have covered them in English in later videos. Like: All Creational Design Patterns in 1 video and All Structural Design Patterns in 1 video