I believe that this does not fulfill Interface Segregation principle of SOLID principles. There is no need of insertCoin and presButton in some cases. We should make different interfaces if any state does not want to implement a function. Tell me if I am wrong. I would love to get corrected.
Small doubt is do we really need a State interface on which Vending machine is dependent. I feels like we can have a enum of states or a current state variable based upon that we can give the functionality output
@@rite2riddhi yes there will be more if-else handling. And regarding polymorphism maybe I will use a strategy pattern but one this is I will give try to use the Abstract class with default function definition so that we don't need to define a function with the same functionality in multiple classes
It's kind of strange that states need vending machine to initiate, and vending machine meeds states. Looks like a kind of circular dependency, and becomes more confusing when you think composition in terms of " class has a" property. Also, taking out inventory instance out of vending machine class, and performing operations on it doesn't sound quite good to me. Wouldn't it be more better if vending machine rather exposes some methods to operate on inventory, rather than giving off its internal objects to outsiders ?
For 2 , yes have added addProductToInventory() in the Vending Machine itself. User will only interact with VM. I focussed on the main problem , hence skipped few things. For 1 , it won't be a cyclic dependency. Again , as I said no design is perfect , and it is not possible to come up with a flawless design in a 1hr interview.
Are you passing the object of the vending machine into all three states' constructors as a reference or a copy of the object? I mean all three states is working on the same instance of vending machine?
In an actual lld interview, do we need to write the whole methods and class or just a skeletal design with the classes and methods just declared and not completely implemented?
I believe that this does not fulfill Interface Segregation principle of SOLID principles. There is no need of insertCoin and presButton in some cases. We should make different interfaces if any state does not want to implement a function. Tell me if I am wrong. I would love to get corrected.
A much needed content. Very few people are there who create videos on this topic. Thank you for your initiative 😁.
Pleasure
Thank you so much, Mr. Riddhi.
Consie & Informative
Very helpful video, at a time when there is a dearth of LLD resources. Thank you for making these ❣
Riddhi, could you please share the git repo link for the same?
@Riddhi could you please share the github link of this code ?
this was highly required. thanks da.
Amazing content as many of the companies are asking LLD questions in their SDE-1 (e.g - freshers) interviews.
Thank you ❤️
how can a person write such a big LLD code in just 1 hr ???
Amazingly explained much needed one😃😇
Thank you
Small doubt is do we really need a State interface on which Vending machine is dependent. I feels like we can have a enum of states or a current state variable based upon that we can give the functionality output
Won't that result in a lot of if else handling? How would you achieve runtime polymorphism?
@@rite2riddhi yes there will be more if-else handling. And regarding polymorphism maybe I will use a strategy pattern but one this is I will give try to use the Abstract class with default function definition so that we don't need to define a function with the same functionality in multiple classes
@@Kapil_Sharma_Engineer using multiple if else might not be good for code readability. But yes , again design is an open ended discussion. 😅
@UCKyTTBdDH3I%F0%9F%98%87635HQMrPvz_A Completely agrees every person has their own view to look at the problem and give the solution accordingly 🙂
Thanks sir very helpful video 😊❤️
Pleasure
I really liked the design as well as the explanation. Please create more such LLD design content👍
Thanks abhishek
Also can you please wrap the whole content in single playlist, so it will be easier for me to track all the videos. Thank You.
Sure
@@rite2riddhi can you please provide the gjithub link of this code ?
It's kind of strange that states need vending machine to initiate, and vending machine meeds states. Looks like a kind of circular dependency, and becomes more confusing when you think composition in terms of " class has a" property.
Also, taking out inventory instance out of vending machine class, and performing operations on it doesn't sound quite good to me. Wouldn't it be more better if vending machine rather exposes some methods to operate on inventory, rather than giving off its internal objects to outsiders ?
For 2 , yes have added addProductToInventory() in the Vending Machine itself. User will only interact with VM. I focussed on the main problem , hence skipped few things.
For 1 , it won't be a cyclic dependency. Again , as I said no design is perfect , and it is not possible to come up with a flawless design in a 1hr interview.
Can you please explain any idea on how to implement online payment in place of adding a coin .
do u have a git hub link
Great explanation
Thanks GOAT
Are you passing the object of the vending machine into all three states' constructors as a reference or a copy of the object? I mean all three states is working on the same instance of vending machine?
Right.
Where is the github url to find the code ??
is there any github repo for this design?
In an actual lld interview, do we need to write the whole methods and class or just a skeletal design with the classes and methods just declared and not completely implemented?
Depends. In an lld interview , important functions you have to write. For machine coding , you have to write everything.
Hi, Thanks for the helpful tutorial. If possible kindly share the codebase in a repository. Regards!
Great explanation! Can we use the same design pattern to design a shopping cart?
instead of throwing illegal state can we sent some warning and be on same state
can we get the source code link as well @Riddhi Dutta
need more LLD videos like this ....please
where can i get the code?
Great stuff
Is this code available somewhere?
Can you post the link to GitHub repo?
Amazing video
Great explanation. Can you please share link to this code repo
plz share the code link
also plz make a video on elevator, distributed cache, splitwise. 😁
Next singleton then elevator
@@rite2riddhi bro please maintain consistency in this series and increase frequency of making videos
pls share github link
It will be very helpful when you share the github link
you explain nicly but i am getting error in this ,,,, might be missing something so if possible provide the source code of the pattern
give code plz
bhai i wanted to ask, how important is LLD for freshers? and especially for campus placements
Not that important but good to know before joining any company
@@rite2riddhi okay, thanks
bro plz add github links for all these questions too
To reduce echoing and delay in the recording point the microphone opening towards the sound source (your mouth). Please don't record the room space.
Hey this is an old recording. Sound is sorted now.
This feels like it breaks Liskov's substitution principle
sir MIke and Voice is not clear and Sir on more thing that is You talking very fast
Wow
Dude
You explain very fast, need extra effort to understand. Didn't like this tutorial.
Oh so sorry to hear that.. I would try to be slow from next time. You can watch it at 0.75x for now.
Exactly.
I guess you could have improved the design more by not create Objects of each state
Why are you unnecessarily violating interface segregation just to explain a state design pattern?