Hi, in this video we have covered #decoratorPattern out of many design pattern which is asked in Low level system design interview. ➡️ Become a Member: / @conceptandcoding
I always wondered why "is-a" and "has-a" relationship between objects is even worth mentioning, but now I know just how important they are. It's amazing how a small detail like this can completely change the way we approach programming.
I worked in both product and service industry of small, medium and large size company, i can see the clear understanding and explanation by the narrator on each of the topic and make an analogy to live code in my work. Very well explained in details, that too free of charge ,i recommend these videos to all the freshers or laterals who are working in java for upskilling.
Wish had explored your channel a bit earlier, awesome content on Low-level design(one-stop solution), Just feedback if you can arrange the videos of the playlist in what order to watch it will be really great for people.
Thank you Yash, not sure if youtube does not show playlist title and description, i have mentioned in both the place that Start from bottom and move Upward, let me check
public class PizzaShop { public static void main(String[] args) { BasePizza base = new VegDelight(); System.out.println(base.cost()); BasePizza customPizza = new ExtraCheese(new Mushroom(new Farmhouse())); System.out.println(customPizza.cost()); } }
Such awesome content, then its free. i cant explain how satisfied i am satisfied with your content. Thanks a lot bro. i have one request bro, whether you provide content free or paid, it does matter. just keep up. i have seen lots of videos and read books regarding design pattern. nobody explained like you. one thing makes your content unique, you deeply explain OOP concept behind design pattern.
really thank you sir for your huge efforts, but sir, if we keep a final ingredients price Map in Base Pizza itself, and keep Topping Map containing topping and its frequency, this can be solved much simply for calculating the price, but then again that solution is not scalable ig when toppings list and price need to be updated, thanks again.
this video is a GEM to the whole community, that too by a GEM..... hats off 2 u sir.. all this premium content for free , not possible on this whole planet itself,.... wish the java playlist would also become public / free someday , so that it can reach to every deserving candidate who cant afford the subscription at that point of time... s teachers like you are rare to find, your knowledge is uncomparable...
Thank you sir for this Amazing content. I have only one question that for every layer we have to create a new class so if our application will scale too much in that case we might have thousands of layers (Not specifically Pizza problem) so how can we solve that ?
Hi, Thanks for the great explanation. One small request could you please share the notes and the code that you are using for the explaination in each video. It would be beneficial.
Thanks for the great content! Your videos are easy to understand. Can we please reorder the videos in the order, currently its in reverse order and we have to play videos manually each time.
In my approach, I used an interface for defining a behavior and then created multiple concrete classes implementing this interface, each representing a different behavior. This seems somewhat similar to the Decorator Pattern, where each decorator wraps an object and adds its behavior. However, I'm struggling to see a significant advantage of the Decorator Pattern over my approach in terms of scalability, flexibility, and maintainability, especially when considering the addition of new behaviors. In both cases, adding a new behavior seems to require just adding a new class without modifying existing ones. Could you help clarify the specific advantages of using the Decorator Pattern over this approach?
You have created A,B C different concrete classes. If you want to create new concrete classes with properties of lets say B , with decorator pattern you will have B1 , B2 etc. But without decorator pattern you might have to write more code to not only include the property of B but also its own new property. I hope this helps.
Super clear, I had a doubt: So according to this example "ExtraCheese" is a BasePizza due to indirect inheritance. So in Vehicle example, the decorator would extend the BaseVehicle. Power Steering would inherit from decorator and in-directly have a "is-a" relationship with BaseVehicle, right So in a way we are saying power-steering is a BaseVehicle so is it right? As power steering is not a Vehicle rather its a feature
Hi Sir, I have 1 question, when both the classes, ExtraCheese and Mushroom have the BasePizza object, then why not add it as part of the ToppingDecorator class itself?
I have the same question. Since the Pizza problem comes more in a object creational use case, wouldn't builder pattern fit more for this use case. Decorators are used to modify the functionality of an object in runtime. Using decorator for object creation puts the object in an inconsistent state till all the decorators are completed. In real scenarios, decorator would be useful, when we need to stack up the operations like encoding a file and then compressing etc.
One very important question sir ji, when to interfere and when to use abstract can u make a detailed video in this, i think this will solve many questions of LLD in a thinking way
Yes, i know this, but while in interview when we say that i will create an abstract class or interface or concrete class they always ask why so? Why not interface inplace of abstract class, this is has been asked alot. So just a request when ever u make any any interface or abstract class please tell us the why interface or abstract please 🙏
Firstly loving your videos! So thanks for that Q. Is this really good to do something like new ExtraCheeze( new ExtraPanner(new FarmHousePizza())))... B'coz not Basepizza object in ExtraCheese already contains a topping of ExtraPanner.... While if we were not to use Decorator design pattern... We would have had all the toppings on same level... (May be with a boolean flag) It might matter if we don't want cheese on top of panner but panner and cheese mixed very well... (Sty could not think of a better example)
Why are we using ToppingDecorator? If we are anyways inheriting Extracheese then can't we inherit it directly from BasePizza as we aren't doing anything in ToppingDecorator class?
Hi great videos. Can you please share the notes or code that you writing ? Moreover, when will the whole LLD playlist be completed? Eagerly waiting to complete all.
Hello sir, first of all thank you for this amazing content ❤.... I hv one question why BasePizza and ToppingDecorator abstract class are abstract classes not interface. ... Just wondering when to use abstract class and when to use interface
Generally both purpose is same to hide the implementation. Interface provide 100% abstraction, while in abstract class you can also implement some methods which are common to child classes
I feel an improvment to this can be rather than creating concrete class for each topping create enum topping list class to dynamically update price for each topping
this code still maintains 'is-a' and 'has-a' relationship. So that is the requirement of decorator pattern . But here my concern with enum is not decorator pattern but with scalability and managebility lets say i want to add more methodd apart from Cost method like TotalCalories, totalProtein , totalCarbs etc. (lets say 10 -20 methods like this) how easy with enum to support this.
Hello Sir, first of all thank you very much for the amazing content! I have one doubt. For interviews, are all the design patterns necessary ? Becoz it would be difficult to remember all of them 😅.. How much is expected from us if we have 2-3 years experience ?
Thank you. See it's a very valid question, nobody can remember all these designs patterns. Couple of things: - How many design patterns is sufficient? Very difficult to answer, what interviewer can ask, we don't know right. - How to remember all? We don't have to, just try to implement design patterns with your own examples, whatever examples i used take it as a reference and then try to implement with different example. It will help you to remember in which usecase what has to be done. Keep 5-6 design patterns on your finger tips which is very frequently asked.
Hi, Suppose we have an abstract pizza class and an abstract toppings class which are inherited by concrete classes . Now, every pizza class has a list of toppings . So, when we calculate the cost, we just iterate over that list and compute the total cost. I have a big doubt that if only has-a relationship is solving this problem. Why do we need such a complex structure of has-a and is-a relationship existing at the same time and what extra advantage does decorator pattern bring into picture ?Looking forward to your reply to this question.
okay, could you please tell me, how you would solve the scenario where you have 1000s of combination like BasePizze, BasePizze + cheese , BasePizza + mushroom, Veggie + cheese and go on...... The biggest advantage decorator pattern adds up is control on number of classes if there are so so many combinations possible.
@@ConceptandCoding Thanks for your reply. Lets suppose Base pizza is extended by two Pizza class Veg and Non Veg Pizza. I have another ExtraAddOn class which is inherited by say cheese, mushroom, paneer and so on ... Now, I have a " vector extraList; " in Veg and Non Veg Pizza class. So, whatever combinations of ExtraAddOn you need, you can add to that list and calculate cost. Only thing is that you cannot mix the base Pizza options, but i don't think that's the requirement here. Am i thinking it wrong ?
Hi, I understood this clearly, But I have a small doubt regarding Abstract class vs Interface. Can't we use Interface in BasePizza and ToppingDecorator, rather than using Abstract class? Other than this, I understood everything. Super explanation sir.
I have a question, when we create the base parent class... how we can decide to take interface or abstract. I think both will work fine. So which one to choose in that case, could you please give a little clearity.?
Strategy Pattern & Decorator seems alike to me like IStrategy even BasePizza Can have only HAS-A relation with ToppingDecorator or list (to calculate cost for all types of toppings) right. Please help me to understand the difference , By the way thanks for the videos :) #Concept&&Coding
I think main task of Strategy Pattern is to remove redundant code where as Decorator Pattern is used to solve the problem of maintainability of our classes.