16. Design Vending Machine | LLD of Vending Machine | State Design Pattern | LLD interview question

  Рет қаралды 77,938

Concept && Coding - by Shrayansh

Concept && Coding - by Shrayansh

Күн бұрын

Пікірлер: 319
@namansaraswat9691
@namansaraswat9691 2 жыл бұрын
This is by far one of the best and very easy to understand lld video I have seen.
@shobhitarya1637
@shobhitarya1637 2 жыл бұрын
Wow..This is a very informative and detailed low level design video. Thank you Concept && Coding. There is one thing instead of using creating state using new operator, we can use controller containing objects of all states. Because using new operator, every time vending machine run, new objects created.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thanks, Yes Shobhit, actually instead of creating new object Singleton object should be used but for easy explanation don't want to include another design pattern and concentrate only State design pattern only. But that can be easily enhanced.
@AkashShukla-ny9wu
@AkashShukla-ny9wu 6 ай бұрын
Liskov: subclass should extend the capacity of parent class not narrow it down. Are we following this principle on state pattern
@ajazahmed5079
@ajazahmed5079 Жыл бұрын
nicely explained, got to know about State Design Pattern. Please keep uploading such LLD Questions for more understanding
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@ayushvida
@ayushvida Жыл бұрын
Thanks a lot for detailed explanation
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Glad it was helpful!
@HarshChoudhary-v9v
@HarshChoudhary-v9v 6 ай бұрын
One of the best video i have seen so far.
@aalokkumar5662
@aalokkumar5662 Жыл бұрын
Really nice video and your explanation is better than others many one.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thank you
@tarunkundhiya5196
@tarunkundhiya5196 Жыл бұрын
Nice Video! One point ISP from Solid principle says "Clients should not be forced to depend upon interfaces that they do not use“. But we are having those different states implement the State Interface which are having all the methods which are not applicable to them. I think we should also find a way to fix that. But good content. Thanks!
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Yes you are right, later on i thought it would be better to use abstract class instead
@tarunkundhiya5196
@tarunkundhiya5196 Жыл бұрын
this would definitely reduce the code, I think creating multiple interfaces as per ISP is not the right solution here as there would be many interfaces and it would look like over-engineering somehow. Can be done however if the operations are less in number.
@sourabhchoudhary7289
@sourabhchoudhary7289 Жыл бұрын
@@tarunkundhiya5196 The thing is we can not stop the user from pressing the wrong button, Suppose we are in the Has money state, and if the user presses the dispense button, we must have defined behavior for wrong operation as well. so it is necessary(in this case) that all stated should define all the methods(Intended or default behavior). Hope it makes sense.
@mohammadkaif8143
@mohammadkaif8143 Жыл бұрын
@@ConceptandCoding Can you please let me know how to use abstract class method here ??
@bhaveshshah3405
@bhaveshshah3405 Жыл бұрын
In my opinion, default methods were introduced in Interface, so that new functionalities can be added to implementers without breaking the existing contracts. If want to force error, have default methods that throws exception and implementers will override only required default methods. This way implementers will be a lot cleaner.
@anirbanhaldar4640
@anirbanhaldar4640 2 жыл бұрын
Wow! very informative and detailed LLD video..keep going! 👏👏👏
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thank you
@arnabbhattacharya825
@arnabbhattacharya825 2 жыл бұрын
What if we select the product first and calculate the money required, and then insert the coins, then exception handling of insufficient money might be easier?
@shruthakeerthis4549
@shruthakeerthis4549 2 жыл бұрын
Very well explained !! I have two doubts, please ignore if this is a trivial one: 1)Once we refund the coins, should we update the coins list too ? 2)in dispense Product method, should we check if the item customer asked gor is available or not before updating the as sold out ?
@santosh_bhat
@santosh_bhat 2 жыл бұрын
Both are very valid questions: 1. Yes, it is important to empty the coins list and then change state to idle. 2. I don't think this check is required since there is no concurrency, and the user can actually see that product is available
@rashidsiddiqui4502
@rashidsiddiqui4502 Жыл бұрын
For the 2nd part, we can refund the money, so the vending machine will go from selection state to the idle state, after returning the money to the customer.
@PujaSingh-qg5ln
@PujaSingh-qg5ln 6 ай бұрын
Thank you. Very well explained and easy to follow and understand.
@HariSarvotama
@HariSarvotama 2 жыл бұрын
Thank for the informative videos . Really helpful while preparing for the interviews. I have few doubts here . 1) in this the SOLID principle we mention that we shouldn't make classes which we don't use but in the State Design pattern , we are creating a lot of classes just to throw exception . is it optimal or accepted in the industry ? Need your opinion on this . Thank you
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
It's not breaking Interface Segregation Principle. What Interface Segregation principle says : You should not force the Concrete class to implement the method. So lets understand this Line with an example: I have an interface Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) And say Duck has method "quack" , "fly" and "Swim". Now lets say, i am adding one more Concrete Class, "Rubber Duck", Now it breaks Interface segregation Principle, why because Rubber Duck can never Quack and never Fly. But still we are forcing RubberDuck class to implement "quack" method and fly method and throw exception. Rubber Duck can NEVER quack and fly. Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) -> Rubber Duck (Concrete class) *breaks interface segregation principle But in Vending Machine, all are the valid operations of a Vending Machine Interface, Vending Machine can do all operations, just it depend upon the state, but say in future we can extend and allow some operation in existing state right. Hope it clarifies.
@akshitbansal5651
@akshitbansal5651 Жыл бұрын
@@ConceptandCoding doesn't this violate liskov substitution principle. Now we can't replace any start object with another state object?
@ThePriyeshpandey
@ThePriyeshpandey Жыл бұрын
@@ConceptandCoding In SOLID principles, I think this is breaking Liskov Substitution Principle, which states that we should be able to replace objects of same types without breaking the functionality. I have an alternate solution for this, we can have a State Interface and then specific State Interfaces for each type of state. State Interface(Base Class), should contain only one method, i.e isActive: which should tell weather the state is simply active or not). In vending machine flow or any state transition flow, only one state can be active at a time. Improvement is, instead of forcing each state to implement a not required method, we can simply check if the state is active or not, whenever there is an operation we want to trigger on that state, if state is not active we simply show a message/exception that this operation is not allowed at the moment. Handling of operation can be governed by a runner method. The responsiblity of runner method will be to change state of the vending machine based on the operation chosen by the user, and call required method of the state, only if the state is active. (Let me know if there is any drawbacks of this approach.)
@dangerousstrikercr7731
@dangerousstrikercr7731 8 ай бұрын
@@ConceptandCoding But this doesn't hold true for all the states, for eg. We can never refund money from the idle state. So ideally some segregation of methods should be there by creating some more interfaces
@mloki9201
@mloki9201 2 жыл бұрын
Whenever we go to idle state we initialize coinsList of vending machine as empty. So there is no way that vending machine can store coins received from multiple customers. Shouldn't we have 2 variables in Vending machine class. 1. overallCoinsList 2. currUserCoinsList So when we refund full we can just empty currUserCoinsList. And if we don't refund, we can add currUserCoinsList to overallCoinsList. PS: Thanks for making LLD videos. They are super helpful :)
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thanks Mustafa for input
@ritwik121
@ritwik121 2 жыл бұрын
Thanks for all the lld videos. Hope you will add more videos to your ongoing LLD Playlist.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Yes, its in WIP, currently i am adding couple of HLD videos thwn will switch back to LLD
@nishantlakhara4127
@nishantlakhara4127 Ай бұрын
Very easy to understand explanation
@akankshagaur845
@akankshagaur845 Жыл бұрын
Very beautifully and conceptually explained.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks a lot 😊
@harshinredzone
@harshinredzone 2 жыл бұрын
Ye badhiya tha Guru 😍
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
:) thanks
@karanbangia14
@karanbangia14 Жыл бұрын
Hey, one question why are taking money before placing order, doesnt this adds more complexity? we should select product then collect money
@Mohit_Gupta24
@Mohit_Gupta24 8 ай бұрын
One observation: Instead of creating a new state object on every state change operation, we can instantiate them in the Vending machine class constructor. Also, the vending machine itself can have these operations as its behaviour and delegate to the state, instead of getting the state from vending machine in the main class. So, the vending machine delegate the request based on the current state without knowing much to the client(main class here).
@pritishn6350
@pritishn6350 6 ай бұрын
I agree, the contracts needs to be attached to Vending machine. Its a standalone box. State machine is an overkill.
@elliotalderson4333
@elliotalderson4333 2 жыл бұрын
As a an absolute beginner I only understood the first half. Can you elaborate the second half concepts such as how you are structuring the java code and why in such way? It wud be very nice if you make video on absolute basics for beginners such as "LLD pre-requisite" video.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Hi Elliot, pls start from the second video, SOLID principles, its the beginning of the playlist. Vending machine is the latest video, thats why i kept it on top, i will move it to the bottom of the playlist
@elliotalderson4333
@elliotalderson4333 2 жыл бұрын
@@ConceptandCoding ok
@AishaSharma-pn8fl
@AishaSharma-pn8fl 5 ай бұрын
I remember you saying that chain of responsibility pattern is used to design ATMs, Vending Machines and logger. Why haven't we used chain of responsibility here then?
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
we can, but i want to demo state design pattern here, so vending machine can be done via state pattern too. pls check ATM design, i have used both State and Chain of responsibility pattern
@nikhilmadaan29
@nikhilmadaan29 6 ай бұрын
Best so far
@saksham483
@saksham483 2 жыл бұрын
You are creating 1 interface with all operations. The class implementing the interface has to override all methods regardless of whether that operation is needed in that class or not. This goes against the Interface segregation principle.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
It's not breaking Interface Segregation Principle. What Interface Segregation principle says : You should not force the Concrete class to implement the method. So lets understand this Line with an example: I have an interface Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) And say Duck has method "quack" , "fly" and "Swim". Now lets say, i am adding one more Concrete Class, "Rubber Duck", Now it breaks Interface segregation Principle, why because Rubber Duck can never Quack and never Fly. But still we are forcing RubberDuck class to implement "quack" method and fly method and throw exception. Rubber Duck can NEVER quack and fly. Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) -> Rubber Duck (Concrete class) *breaks interface segregation principle But in Vending Machine, all are the valid operations of a Vending Machine Interface, Vending Machine can do all operations, just it depend upon the state, but say in future we can extend and allow some operation in existing state right. Hope it clarifies.
@ayush146235
@ayush146235 8 ай бұрын
@@ConceptandCoding May be it is better if we make all operation as Commands and while executing command check if Vending Machine is in allowed state or not. This will help us in reducing duplicacy.
@satyamanand4391
@satyamanand4391 5 ай бұрын
​​@@ConceptandCoding Then in that case we should have created State as abstract class and have some default behaviours defined for all the methods. Now each states need to only override the methods that it supports. By adding all the methods to a single interface here it is indeed violating interface segregation principle.This approach strikes a balance between code reuse and adhering to design principles
@LokeshRajput-qw9il
@LokeshRajput-qw9il 3 ай бұрын
​@@satyamanand4391after java 8 we can have default method implementation in interfaces also
@LokeshRajput-qw9il
@LokeshRajput-qw9il 3 ай бұрын
​@@ayush146235didn't understand this, can you explain
@shivamyadav4846
@shivamyadav4846 6 ай бұрын
Hi, as this is failing ISP rule of SOLID. How I am thinking to implement it. in State we have only Single method handleRequest(event); all states will implement this. And we have an service Class where all vendling machine function will be defined. State class will have this service class obj. so in perticular state we can use switch case according to req obj and default will be this req can't be served in this state.
@nithishkumars1657
@nithishkumars1657 12 күн бұрын
dont you think it will become a strategy pattern. I too have the same doubt. For sure, the interviewer will ask the violation of SOLID principles here.
@santhoshkumar-rx2js
@santhoshkumar-rx2js 2 жыл бұрын
Thank you Shrayansh.
@pietech1694
@pietech1694 4 ай бұрын
The video content is quite good.... Please add the git link for free video so that we can understand the code base in better way.
@jainamshah3691
@jainamshah3691 Жыл бұрын
Hii shreyansh What if there is one operation that is always available in each state , then there will be code repeatition , right? And if there are multiple such operations then there ll be huge code duplication So i thought can we use strategy design pattern under a state design pattern Also i am not able to understand how we can use strategy here under a state.. Thanks, Jainam Also do you have any doubt stream like telegram or some social or youtube comment is the only stream for asking doubts
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Hi, yes you are right, we can avoid this code repetition, either using abstract class too. But you can definitely try to implement it with strategy pattern, as there can be many ways to implement it, eager to see your solution and then we can discuss more on that
@jainamshah3691
@jainamshah3691 Жыл бұрын
@@ConceptandCoding thanks for the prompt response,sure I ll create a solution and then we can discuss on that Thanks, Jainam
@santosh_bhat
@santosh_bhat 2 жыл бұрын
Very good explanation and design, i believe we could change the state to HasMoneyState if Vending Machine encounters that the required amount is less than inserted coins so that user can insert more coins or should we refund and throw exception like we do. As a whole i get the intent State pattern is solving.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Thank you
@LOVEPREETSINGH-ft6nd
@LOVEPREETSINGH-ft6nd 7 ай бұрын
nicely explained . But i have one doubt , why can't we use the abstract class instead of interface and move all default implementation to the abstract class so that we can avoid the code duplication.
@ConceptandCoding
@ConceptandCoding 7 ай бұрын
right, in comment section i have mentioned this to avoid duplication
@vijaypatneedi
@vijaypatneedi 2 жыл бұрын
Great content, maza aagya..
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thanks Vijay. Pls do share it with your connections.
@vijaypatneedi
@vijaypatneedi 2 жыл бұрын
​​@@ConceptandCoding udit agarwal, think software.. channels jaise high quality content hai ye❣️ I'll share 👍
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thanks a lot Vijay, really thank you for your kind words. Its a new channel so reach is less, so this comment really means a lot to me.
@saiv-c5h
@saiv-c5h 3 ай бұрын
since in java class can implement multiple interfaces, we can create separate interface for each function in state class and can provide them default implementation, and states can implement only required interfaces and in this way it can satisfy liskov substitution principle and interface segregation principle. Correct me if i am wrong guys ?
@ConceptandCoding
@ConceptandCoding 3 ай бұрын
@@saiv-c5h right, and I have mentioned in comment section too that this can be improved same way you mentioned
@saiv-c5h
@saiv-c5h 3 ай бұрын
@@ConceptandCoding thanks for confirming this shreyansh. This was indeed a best explanation i have ever seen till now
@sunny0287
@sunny0287 2 жыл бұрын
Great Explanation, easy to understand for any one .... One Question Is this State design pattern is not violating the SOLID principle [Interface segmented principle] ??
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
It's not breaking Interface Segregation Principle. What Interface Segregation principle says : You should not force the Concrete class to implement the method. So lets understand this Line with an example: I have an interface Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) And say Duck has method "quack" , "fly" and "Swim". Now lets say, i am adding one more Concrete Class, "Rubber Duck", Now it breaks Interface segregation Principle, why because Rubber Duck can never Quack and never Fly. But still we are forcing RubberDuck class to implement "quack" method and fly method and throw exception. Rubber Duck can NEVER quack and fly. Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) -> Rubber Duck (Concrete class) *breaks interface segregation principle But in Vending Machine, all are the valid operations of a Vending Machine Interface, Vending Machine can do all operations, just it depend upon the state, but say in future we can extend and allow some operation in existing state right. Hope it clarifies
@sunny0287
@sunny0287 2 жыл бұрын
@@ConceptandCoding yeah got it, thank you 👌
@anandrana7340
@anandrana7340 2 жыл бұрын
Thanku Bhaiyaji ...such a wonderful content as always , can we make another class for fillUpInventory and displayInventory methods to follow Solid Principle?
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Ack, i will reply tomorrow.
@Mona_yadav27
@Mona_yadav27 8 ай бұрын
hi shrayansh, This is awesome explanation of the LLD vending machine, just a quick question . I may sound dumb , but as per solid principle. No child class should be forced to implement unnecessary method of an interface. as per this, when we are designing implementation of state interface method we are actually forcing the child state concrete classes to implement other. is there a way we can avoid that . Thanks in advance for your response.
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
yes you are right, we can make it more better by changing interface to abstract class and in abstract class, we can implement the method and throw exception there, now any child class wants to override the functionality, can override it else not required
@shriharikulkarni3986
@shriharikulkarni3986 Жыл бұрын
19:15 Shreyansh, if we throw exception in concrete class , then it violates interface segmentation principle right, don’t implement unnecessary methods. Is state design a good pattern?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
We can have abstract class instead of interface
@shriharikulkarni3986
@shriharikulkarni3986 Жыл бұрын
@@ConceptandCoding even then in concrete class we should throw exception only no
@ConceptandCoding
@ConceptandCoding Жыл бұрын
@@shriharikulkarni3986 in parent class itself we can throw exception, and which ever child want to override the behaviour they can override that method
@WasteMaterial-vr3qe
@WasteMaterial-vr3qe 9 ай бұрын
I am impressed 😄😅
@shashankmishra484
@shashankmishra484 2 жыл бұрын
Hey, thank you for the great content I have few questions 1. The part of UML diagrams and part of actual code with main function you have shown, are both needed to be covered in an interview? Or we showcase and discuss the UML and just verbally tell about the design patterns that can be used? I was given vending machine LLD for half hour, not sure if the whole working code can be written in half hour along with drawing UMLs 2. Follow up on above, is this LLD or machine coding 3. Where do you study all these? educative is the best source I know but it purely concentrates on the UML and not on possible design patterns that can be used Please keep uploading. If you upload faster I will be able to crack my next week's interviews 😛
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Many companies do ask for Coding. If UML is correct and interviewer is okay, then coding completion is not that important. Even we write the code partially after UML, chances are still high for acceptance. I refer "head first design pattern" book for design patterns. Questions solving that comes with an experience :)
@shashankmishra484
@shashankmishra484 2 жыл бұрын
@@ConceptandCoding Thanks. Just one more question How necessary it is remember the signs for association, generalization and all those things? i am particularly talking about the arrow symbols
@Mona_yadav27
@Mona_yadav27 8 ай бұрын
Thank you so much . This helps 🎉
@ayushupadhyaya7656
@ayushupadhyaya7656 8 ай бұрын
Returning the change to user can have follow up question in form of famous coding question-> Coin change
@shubhamtiwari7704
@shubhamtiwari7704 2 ай бұрын
Hi shreyansh, How to decide which feature is object there are many posibilities......while discussing the rough flow you generally use this terms lets decide objects......please reply
@amitgupta-or5nm
@amitgupta-or5nm 2 жыл бұрын
Nycly explained
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thanks
@darkstudio3170
@darkstudio3170 2 жыл бұрын
Really well explained. Thanks a lot
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thank you
@nithishkumars1657
@nithishkumars1657 12 күн бұрын
For sure, the interviewer will ask about the violation of SOLID principles here. I also have the same doubt. Be preapared for the followup questions. OpenAI Justification: The Liskov Substitution Principle (LSP) and the Interface Segregation Principle (ISP) are indeed important principles in object-oriented design. LSP states that if a program is using a base class, then the reference to the base class can be replaced with a derived class without affecting the functionality of the program. In the context of the vending machine design, if a state (base class) is replaced by its specific state (derived class), the functionality should not be affected. If a derived class is restricting the functionality of the base class, then it might be violating LSP. ISP, on the other hand, states that no client should be forced to depend on interfaces they do not use. This principle is about business rules to clients that shouldn’t know about. If a class is forced to implement an interface and provide implementation to methods that it doesn’t use, then ISP is violated. In the context of the vending machine design, the State interface might seem to violate the ISP because it declares methods that may not be meaningful for all states. However, it’s a common situation in the State design pattern. If you find this to be a problem, you could consider breaking down the State interface into smaller, more specific interfaces. But, this might complicate the design and make it harder to understand and maintain. Remember, design principles are not absolute rules but guidelines. Sometimes, they might seem to conflict with each other, and it’s up to the designer to make trade-offs based on the specific context and requirements.
@ConceptandCoding
@ConceptandCoding 12 күн бұрын
rightly pointed out, we can change the interf to abstract class, so that child class should not implement the method unnecessarily.
@tejasshaha6629
@tejasshaha6629 2 жыл бұрын
Great explanation. Thank you.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Thanks 🙏
@amiyamishra9858
@amiyamishra9858 9 ай бұрын
Hello Shrayansh,Thank you so much for the nice explanation.One enhancement I can think of ,Please correct me if I am wrong: we should update the coinList of VendingMachinr to empty after dispensing the prouct or after doing refund/change else during next time calculation for amountPaidByuser will be wrong..
@gyanaranjanmallick9714
@gyanaranjanmallick9714 Жыл бұрын
Hi Shreyansh, I have one small query - 1. In your "SOLID principle" video you took the example of restaurant employees, waiter and chef to explain "interface segmented principle" so that chef doesn't have to implement waiter's methods and vice versa. In this case of vending machine states, should we follow the same way and implement different methods for different states? Or is there any particular reason because of which, it doesn't really matter if we follow "interface segmented principle" or not in this particular vending machine case. Thanks, and really appreciate your work.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Ack of the question.
@ayushagarwal2504
@ayushagarwal2504 Жыл бұрын
I have the same question. I think here, we can instead make State a concrete class and use strategy pattern to inject different behaviours of the different functions in the state class.
@NeverGiveUp186
@NeverGiveUp186 Жыл бұрын
Hi Shrayansh, great explanation as always!! I had one doubt. In the video on Chain of Responsibility (CoR) pattern, you had mentioned that we would be using CoR pattern for Vending Machine/ ATM type questions. But in this question, you have used State Pattern🤔. Can you please explain a bit about the choice of pattern selection? Thanks!
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Hi Sarvesh, in ATM i did use COR pattern. But see when COR can be used when you go sequentially and check "hey can you fulfill the request, if not go to next", so in vending machines, currently we are directly putting slot number but let's say if there is a requirement that we have to go each slot sequentially and see, if request can be fulfilled then we have to use CoR for implementing that part. So it will become state + COR like an ATM.
@NeverGiveUp186
@NeverGiveUp186 Жыл бұрын
@@ConceptandCoding Ohh..ok. Now it is clear. Thanks a lot!!
@paraskhare8116
@paraskhare8116 Жыл бұрын
​@@ConceptandCoding Hi Shreyansh, what in the case of giving the coin changes in Vending Machine, in that exact state we can apply the CoR. As it is almost act like an ATM machine but in a different way.
@debjyotichattopadhyay6679
@debjyotichattopadhyay6679 5 ай бұрын
This is really amazing and very informative solution, but adding all the methods in interfaces (even those methods that are specific to certain states) will violate the I of the S.O.L.I.D principle, correct me if i am wrong
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
we can change it to Abstract class and provide default functionality there
@Naman-u7q
@Naman-u7q 11 күн бұрын
You said that we need machine object in all states, but why HasMoney and SelectionState doesn't have the machine object?
@BTECE_RajdeepSinghTanwar
@BTECE_RajdeepSinghTanwar Жыл бұрын
Great explanation!! I have 1 doubt, why do we need to provide codeNumber in dispense product method, the product is already choosen so we should store the choosen codeNumber in vending machine only. Otherwise there is chance that wrong item get dispensed by calling dispense product with wrong code number. Correct me if I'm wrong.
@rv0_0
@rv0_0 Жыл бұрын
User is not calling the dispense product method, it is a chained method call from the selection state
@MohitSingh-br7ud
@MohitSingh-br7ud Жыл бұрын
Shouldn't the ideal state should go to the select product state first and according to the product selected(is not sold out) we should insert coins? Also for the insertion of coins let's says product was of 25rs and I have 3 coins of value 10, in that case, product should be dispensed along with 5rs as a refund, and If I have not inserted the coins making the sum >= 25 the vending machine should keep on blinking and ask for money or should give the option to cancel and refund. Also when the product is going to expire or when the freq of that product is low then a notification should be sent to the owner. Actually, that's the exact question I was asked in Agoda (Bangkok Thailand location). I was stuck at the blinking part of vending machine after product selection. How would you have approached it?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Hi Mohit, based on the State design pattern approach, could you please try to implement the respective changes which you have mentioned. If you get stuck, we will definitely discuss
@prashantgupta6160
@prashantgupta6160 2 жыл бұрын
Hi Shrayansh, I found your video very informative. Can you make a video on HLD and LLD of one system like vending machine itself, what would be HLD for this. I get often confuse what to tell in HLD and what to tell in lld round, should I discuss API contracts / DB design in LLD round or not... so there is a disconnect between HLD and LLD, can you please make a video in this topic as well.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Sure Prashant. HLD and LLD are very different. HLD is at top level, how different components put together for any application like Load balance, Microservices, Cache, What DB to use etc etc. But LLD is OOPs concepts more close to Coding. Objects involved, classes, their relationship. LLD does not bother about what DB to use, Load balancer, cache, CDN and all. But if you have doubts we can discuss more.
@shivshankar5717
@shivshankar5717 Жыл бұрын
Correct me if i am wrong but I dont think the State interface which you made needs to have all those function, it violates the Interface Segregation principle and Liskov Substitution principle of SOLID principles, like for example while in idle state to have refund function is meaningless and also by adding the exceptions while defining function limits the functionality which shouldn't be done as per Liskov Substitution principle.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
It's not breaking Interface Segregation Principle. What Interface Segregation principle says : You should not force the Concrete class to implement the method. So lets understand this Line with an example: I have an interface Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) And say Duck has method "quack" , "fly" and "Swim". Now lets say, i am adding one more Concrete Class, "Rubber Duck", Now it breaks Interface segregation Principle, why because Rubber Duck can never Quack and never Fly. But still we are forcing RubberDuck class to implement "quack" method and fly method and throw exception. Rubber Duck can NEVER quack and fly. Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) -> Rubber Duck (Concrete class) *breaks interface segregation principle But in Vending Machine, all are the valid operations of a Vending Machine Interface, Vending Machine can do all operations, just it depend upon the state, but say in future we can extend and allow some operation in existing state right. Yes there might be different ways to implement, but i used this example to explain state design pattern, hope that pattern is clear?
@shivshankar5717
@shivshankar5717 Жыл бұрын
@@ConceptandCoding Got it, so the crux of the story is that it doesn't break ISP as the vending machine itself is providing those options, we are not forcing it . Thanks man , great content. Keep doing the good work. :)
@DeepakKumar-oc2zl
@DeepakKumar-oc2zl Жыл бұрын
Awesome Explanation of LLD. As you have created Interface which have all abstract methods within single Interface. As per my knowledge, It is violation of SOLID Principle. Can we optimize it in precise way?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Yes we can take abstract class instead.
@siddhantgupta3050
@siddhantgupta3050 Жыл бұрын
doesnt this break liskov substitution principle?thanks for great videos!
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Could you please elaborate how?
@mission_India_2025
@mission_India_2025 Жыл бұрын
@@ConceptandCoding The interface you created had all methods for all states. That means you have to throw exceptions on some methods in few implementations. That made the child classes not fully replaceable for its parent. Also it violates Interface segregation principle. As its LLD interviewer if catches it then it would be a negative
@vishalkumar-bz5mq
@vishalkumar-bz5mq 7 ай бұрын
Hi just one doubt throwing exception from state classes will voilate the Liskov Substitution Principle right.
@yashbansal2526
@yashbansal2526 2 жыл бұрын
Great Content
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thank you
@akashchakrabortty2431
@akashchakrabortty2431 Жыл бұрын
Hi Shrayansh , Thanks for explaining it so clearly.🙂 Just having a doubt- Instead of writing a concreate class of each state where others will throws exception, can we make it as an abstract class?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
yes we can, and its much better than interface
@abhijitmandal9531
@abhijitmandal9531 9 ай бұрын
Hi Shrayansh, very nicely explained thank a lot...just a doubt, when we are implementing State interface, we are throwing exceptions in child for some methods (throw new Exception) here are we not violating Liskov Substitution Principle.
@ConceptandCoding
@ConceptandCoding 9 ай бұрын
yes you are right, we can make it more better by changing interface to abstract class and in abstract class, we can implement the method and throw exception there, now any child class wants to override the functionality, can override it else not required
@prernapundir8020
@prernapundir8020 10 ай бұрын
Hi Shreyansh, I just had one doubt: shouldn't the state transition from one state to another be done by vending machine classe? Something like this individual state should just change the status of the machine, and on that basis, switching to a particular state should be decided by the vending machine class, so that state shouldn't create the object of the transition state every time. Just create the object once in the vending machine and pass it on and if so can we use factory method toe create the objects of states. Please correct me if I'm wrong here.
@souvikpodder9515
@souvikpodder9515 2 жыл бұрын
Hey, The tutorial is of great help clearing most of my doubts in this design pattern. Thanks for your amazing content. I have a doubt while implementing the State implementation we are having lot of methods which we are not implementing and throwing exception, but according to the Implement segregation principal in SOLID design we should not be doing so. My question is why are we not using the common interface for the operations where we don't need to implement all the other unrequired operations?
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Hi, could you pls check this live session which i took kzbin.info/www/bejne/Y4bNm5mwf5pqatk Look for interface segregation part, I think it will clarify your doubt if not let me know
@souvikpodder9515
@souvikpodder9515 2 жыл бұрын
hi @@ConceptandCoding, I gone through the video, got the scenario thanks for the prompt response.
@amanjain7111
@amanjain7111 8 ай бұрын
Seems fine, just one issue. It violates the Interface Segregation principle for all the states, as we all the states need to implement all the methods of State interface, instead it should implement only one. What could be done for that?
@amanjain7111
@amanjain7111 8 ай бұрын
Maybe we can just have a handle function in the State Interface. And accordingly the other states should be implemented.
@tomorrowcut
@tomorrowcut 8 ай бұрын
Hi Shrayansh, Can you please help me with an answer?? Why we are not using chain of responsibility design pattern here?? .. and what’s the trade off between the two??
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
we can. depending upon the requirement. in chain of responsibility, machine has to check each slot one by one and see if request can be fulfilled or not. but it can be done
@tomorrowcut
@tomorrowcut 8 ай бұрын
@@ConceptandCoding Got it, thanks!
@amanchoudhary9107
@amanchoudhary9107 Жыл бұрын
Does initialising the ItemShelf in the inventory class makes sense. Isn't it breaking the S.R.P, Inventory should be worried about just managing the inventory not maintaining the shelf and there initialisation logic.
@UntamedRogueMavrick
@UntamedRogueMavrick 11 ай бұрын
Hi Shreyansh, I liked this session very much. I have one question here, whenever we are changing the state, we are creating the new Object of the state and passing it to setter. And if users are more, more and more state impl object will be created. Can we improve this part of code?
@AyushAgrawal-qm1tr
@AyushAgrawal-qm1tr 2 жыл бұрын
Great content 😀..Can you also share some resources for lld in c++ also
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
LLD in C++ does not matter Ayush. If you understand the object relationship and UML diagram, you can code in any language
@sachinjindal4921
@sachinjindal4921 2 жыл бұрын
Really Good
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thanks Sachin
@bipuljee2996
@bipuljee2996 Жыл бұрын
very well explained brother, would like to have your take on elevator system.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
I have already covered, pls check the complete playlist buddy
@himanshijain8230
@himanshijain8230 Жыл бұрын
Hi Shreyansh, i have one doubt, in the chain of responsibility design pattern video, you said that in case of vending machine design we should the pattern but here you are solving it using state design pattern. So exactly which one should we use?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
you can also design vending machine using chain of responsibility, do try it out. there are many ways to design one system.
@dineshhardasani3414
@dineshhardasani3414 5 ай бұрын
Hi, I think the interviewer might not accept this solution because we are duplicating code here. In this flow, we are adding duplicate code for some interface functions, like refundFullMoney, in both SelectionState and HasMoneyState.
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
we can change it to abstract class
@dineshhardasani3414
@dineshhardasani3414 5 ай бұрын
@@ConceptandCoding Then all classes will have that function, such as refundFullMoney, and we need to override it where we don't want to allow refundFullMoney
@throxe
@throxe Жыл бұрын
Can you kindly make an English version of this Please.. The video is not really useful for some of us English language speakers cos it's mostly in hindu It's such an interesting LLD Design example and rare to find online at this depth and coverage Thank you
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Hi Throxe, i understand that, and thats why i have switched to English and all my videos are now in English only. Regarding this one, i will see, if i can add subtitle or upload in English (in Live LLD Playlist)
@ebtasamfaridy9137
@ebtasamfaridy9137 9 ай бұрын
Doesn't this break Liskov's substitution of solid principle as some states don't implement all methods defined in the interface or base class ?
@ConceptandCoding
@ConceptandCoding 9 ай бұрын
we can change the interface to abstract class and provide the default implementation there. so that child classes should not unnecessarily throw exception.
@Stockfundamentalstelugu
@Stockfundamentalstelugu 11 ай бұрын
I think in state design we are not following the interface segmentation as we said in SOILD right?
@ConceptandCoding
@ConceptandCoding 11 ай бұрын
could you please elaborate why? we can discuss
@rajeevnayan9672
@rajeevnayan9672 8 ай бұрын
@shreyansh, In this design pattern for state interface, Isn't it violating SOLID (interface segregation principal as each concrete class has to implement all the methods).
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
yes you are right, we can make it more better by changing interface to abstract class and in abstract class, we can implement the method and throw exception there, now any child class wants to override the functionality, can override it else not required
@sarveshrawat1462
@sarveshrawat1462 6 ай бұрын
Hey Shrayansh, Doesn't this State Design Pattern violate 'I' principle of SOLID. Why we are implementing methods of a interface which we really don't need to implement.
@ConceptandCoding
@ConceptandCoding 6 ай бұрын
good point buddy, we can change the interface to abstract class and implement the method with default functionality.
@GateCSE280
@GateCSE280 10 ай бұрын
Hey Shreyansh, i have one doubt. This pattern working is nearly similar to what we learned in proxy and chain of responsibility design pattern. Why I said proxy, because if you see we can create layers and the object of mext layer will be created only when the current layer is finished. example: First layer is idle; waiting for user input Second proxy layer: insert coin; once user press submit, go to third layer that is choosing product. Am I correct? Also this pattern, is violating the I of solid principle. Interface segregation. Because different states are unnecessarily inherenting the not required functions?
@ConceptandCoding
@ConceptandCoding 10 ай бұрын
interface can be changed to Abstract class (where we can implement the method, so that all child classes no need to override them) yes it looks similar but they solve different purposes.
@ChandanKumar-rl6df
@ChandanKumar-rl6df 6 ай бұрын
If you are keeping all the methos in Interface and respecting concrete class will implement properly only required methods and throw exception from other methods. Don't you think we are breaking Interface segregation principle from SOLID?
@ConceptandCoding
@ConceptandCoding 6 ай бұрын
we can change it to abstract class and implement the default method there. then child classes no need to implement it unnecessarily
@mintu591
@mintu591 Жыл бұрын
Hello sir, I've a doubt , You taught in the SOLID principle lecture, L says Interface should be such that there implementation class should not implement unnecessary function they do not need but in vending design machine video we are overriding all unnecessary function from State interface Why? Can we create a sperate interfaces?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
It's not breaking Interface Segregation Principle. What Interface Segregation principle says : You should not force the Concrete class to implement the method. So lets understand this Line with an example: I have an interface Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) And say Duck has method "quack" , "fly" and "Swim". Now lets say, i am adding one more Concrete Class, "Rubber Duck", Now it breaks Interface segregation Principle, why because Rubber Duck can never Quack and never Fly. But still we are forcing RubberDuck class to implement "quack" method and fly method and throw exception. Because these feature RubberDuck can NEVER have. Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) -> Rubber Duck (Concrete class) *breaks interface segregation principle But in Vending Machine, all are the valid operations of a Vending Machine Interface, Vending Machine can do all operations, just it depend upon the state, but say in future we can extend and allow some operation in existing state right. Hope it clarifies. Yes one improvement we can do is instead of interface we can take abstract class and all the throw exception repetition we can avoid
@faizulhaq4527
@faizulhaq4527 2 жыл бұрын
@Concept && Coding is it not violating the SOLID principle, as some of the classes does not have implementation of abstract methods
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
It's not breaking Interface Segregation Principle. What Interface Segregation principle says : You should not force the Concrete class to implement the method. So lets understand this Line with an example: I have an interface Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) And say Duck has method "quack" , "fly" and "Swim". Now lets say, i am adding one more Concrete Class, "Rubber Duck", Now it breaks Interface segregation Principle, why because Rubber Duck can never Quack and never Fly. But still we are forcing RubberDuck class to implement "quack" method and fly method and throw exception. Rubber Duck can NEVER quack and fly. Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) -> Rubber Duck (Concrete class) *breaks interface segregation principle But in Vending Machine, all are the valid operations of a Vending Machine Interface, Vending Machine can do all operations, just it depend upon the state, but say in future we can extend and allow some operation in existing state right. Hope it clarifies.
@faizulhaq4527
@faizulhaq4527 2 жыл бұрын
@@ConceptandCoding thanks
@soumyaripan5131
@soumyaripan5131 Жыл бұрын
Thank you!
@nikhildalvi6896
@nikhildalvi6896 Жыл бұрын
Great Video!! 1 question though, can we have the base class as abstract and all the functions in the base class would by default throw Exception, and the child classes would provide implementation for only specific methods they implement. Thinking this w.r.t. avoid duplicate code in all the child classes.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Right, same i did in ATM design. You are right buddy
@shubhamprasad2430
@shubhamprasad2430 7 ай бұрын
@ConceptandCoding doesn't it violate the interface segregation principle? As we are having a big interface and all of the state concrete classes do not need to implement all of the methods
@ConceptandCoding
@ConceptandCoding 7 ай бұрын
change the interface to abstract class . and we can provide default implementation in the abstract class itself
@namansaraswat9691
@namansaraswat9691 2 жыл бұрын
I have one question that here in this solution we have one state interface that is breaking Interface Segregation principal. Is this demerit of this design pattern or it can be modified?
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Naman could you please elaborate, why you think its breaking Interface segregation principle
@samcooper-02
@samcooper-02 2 жыл бұрын
@@ConceptandCoding It is breaking interface segregation principle since not all the methods of the interface are getting used in the concrete state implementations. We are simply throwing exceptions for the method we are not using. And according to the principle we should not force a class to implement methods it does not use. Solution could be to separate the methods belonging to a state in a separate interface.
@theUneditedNature
@theUneditedNature 2 жыл бұрын
@@samcooper-02 Throwing exception or default behaviour is not a dummy implementation of the methods in a vending machine context. Here we are exposing vending machine to a customer and the customer can choose to dispense product in an ideal state. So we need a default/exception implementation here. So essentially its not breaking interface segregation !
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
It's not breaking Interface Segregation Principle. What Interface Segregation principle says : You should not force the Concrete class to implement the method. So lets understand this Line with an example: I have an interface Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) And say Duck has method "quack" , "fly" and "Swim". Now lets say, i am adding one more Concrete Class, "Rubber Duck", Now it breaks Interface segregation Principle, why because Rubber Duck can never Quack and never Fly. But still we are forcing RubberDuck class to implement "quack" method and fly method and throw exception. Because these feature RubberDuck can NEVER have. Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) -> Rubber Duck (Concrete class) *breaks interface segregation principle But in Vending Machine, all are the valid operations of a Vending Machine Interface, Vending Machine can do all operations, just it depend upon the state, but say in future we can extend and allow some operation in existing state right. Hope it clarifies.
@namansaraswat9691
@namansaraswat9691 2 жыл бұрын
I also have same doubt as Samarth. Thanks for clarifying Shrayansh
@neelanshgulati2643
@neelanshgulati2643 2 жыл бұрын
According to interface segregation principle, should we have more fine grained interfaces rather than throwing exceptions from state classes?
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
It's not breaking Interface Segregation Principle. What Interface Segregation principle says : You should not force the Concrete class to implement the method. So lets understand this Line with an example: I have an interface Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) And say Duck has method "quack" , "fly" and "Swim". Now lets say, i am adding one more Concrete Class, "Rubber Duck", Now it breaks Interface segregation Principle, why because Rubber Duck can never Quack and never Fly. But still we are forcing RubberDuck class to implement "quack" method and fly method and throw exception. Because these feature RubberDuck can NEVER have. Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) -> Rubber Duck (Concrete class) *breaks interface segregation principle But in Vending Machine, all are the valid operations of a Vending Machine Interface, Vending Machine can do all operations, just it depend upon the state, but say in future we can extend and allow some operation in existing state right. Hope it clarifies.
@neelanshgulati2643
@neelanshgulati2643 2 жыл бұрын
@@ConceptandCoding I still believe making smaller interfaces like S1,S2,.... and then utlizing them (multiple inheritance) would be better way to go. This will take into account in future we can extend and allow some operation in existing state right.
@mission_India_2025
@mission_India_2025 Жыл бұрын
@@ConceptandCoding no it tells " clients should not be exposed to methods it doesn't need". So I feel the 1 interface with bunch of methods is not needed. It should have the methods needed by all childs only.
@deepak655655
@deepak655655 8 ай бұрын
Is it adhering to "I" of the SOLID principles, as there are many non required interface methods in the concrete classes?
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
we can change it to abstract class and provide a default implementation there so that no child class need to implement it
@deepak655655
@deepak655655 8 ай бұрын
@@ConceptandCoding But still those default implementations will be redundant code in all the concrete classes?
@hiteshbitscs
@hiteshbitscs 10 ай бұрын
One mistake you made I feel Vending machine has array of shelf and shelf has inventory. You mentioned vending machine has inventory and inventory has shelf.
@sabinshrestha9496
@sabinshrestha9496 Жыл бұрын
Hello sir, I want to be member in your youtube channel to see and learn some paid video, but I don't see option to be member in your channel. Does it matter from which country we are ?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
It's a youtube option, generally at home page you should be able to see Join button
@jatinthakwani5370
@jatinthakwani5370 2 жыл бұрын
Great content!
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thank you
@Sushil2874
@Sushil2874 2 жыл бұрын
Awesome explanation !! BTW, which device are you using for writing in OneNote?
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
wacom tablet
@sameerpattanaik9097
@sameerpattanaik9097 10 ай бұрын
the interface state you created, isn't it breaking the interface segmentation principle of SOLID ?
@ConceptandCoding
@ConceptandCoding 10 ай бұрын
we can change the interface to Abstract class and implement a method there so that all child classes will not override the method.
@rajnishsingh6719
@rajnishsingh6719 2 жыл бұрын
pls make some video on java microservices if possible
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
sure
@AmanKumar-dq4mz
@AmanKumar-dq4mz 2 жыл бұрын
I think the very first question will be Scalability, suppose they ask for scaling payment process to accepting UPI / Card along with Cash. 2. Adding display, May be re-arranging the processes will solve some problems, but again few extra feature will lead to design failure. Let me know if I’m thinking in wrong direction.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Good thoughts process Aman. keep it up buddy
@prashantgupta6160
@prashantgupta6160 2 жыл бұрын
@shrayansh, how will be solving the payment scalability issue then?
@ashutoshraturi8574
@ashutoshraturi8574 2 жыл бұрын
@@prashantgupta6160 create an interface with PaymentStrategy, and then extend different types of payment strats such as CreditCardStrat or CashStrat etc.
@zishanshaikh9375
@zishanshaikh9375 Жыл бұрын
hasMoney state should not allow to insert another coin right ? as the coin is already entered in the idle state, correct me if i'm wrong
@ConceptandCoding
@ConceptandCoding Жыл бұрын
yes we can restrict that in our design.
@khimanidhaval1964
@khimanidhaval1964 5 ай бұрын
Why are you forcing the concrete state class to implement a state interface all method or throw an exception? We can use the Interface segregation principle here.
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
@@khimanidhaval1964 right we can change the interface to abstract class and provide the default implementation there
@ehtashammazhar3518
@ehtashammazhar3518 2 жыл бұрын
Hi , your video is really helpful. Could you please make a video about Inventory management System . this was asked in amazon interview.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Noted. Let me add it in my todo list, thanks for sharing.
@PankajGupta-gh9cm
@PankajGupta-gh9cm 2 жыл бұрын
i have one doubt In the solid principle video we have that Interface Segregation Principle in that we have to segregate interface such that it only implements interface of its need and we remove the extra not needed function . so i think State Design Pattern is not following that Principle beacause here Idle State and other States implementing all functions which are not required .in those functions they are just throwing Exception
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Hi Pankaj, the same doubt i have cleared in the Live session kzbin.info/www/bejne/Y4bNm5mwf5pqatk Pls have a look, your doubt will get cleared
@jeethanmontheiro7996
@jeethanmontheiro7996 Жыл бұрын
what is difference between chain of responsibility and state design pattern?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Pls check the Design ATM video, i have covered it in that i have used both, it will clarify your doubt
@NeerajSharma-mz4es
@NeerajSharma-mz4es 6 ай бұрын
Nice Video
@viralipurbey6358
@viralipurbey6358 Жыл бұрын
Thanks for sharing. But how are we following the interface segregation principle here while using state design pattern?
@aniketsharma5221
@aniketsharma5221 Жыл бұрын
It's a tradeoff for this design. We can't always design keeping all the design and SOLID principles in mind.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
It's not breaking Interface Segregation Principle. What Interface Segregation principle says : You should not force the Concrete class to implement the method. So lets understand this Line with an example: I have an interface Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) And say Duck has method "quack" , "fly" and "Swim". Now lets say, i am adding one more Concrete Class, "Rubber Duck", Now it breaks Interface segregation Principle, why because Rubber Duck can never Quack and never Fly. But still we are forcing RubberDuck class to implement "quack" method and fly method and throw exception. Because these feature RubberDuck can NEVER have. Duck (Interface) -> MallardDuck (Concrete Class) -> DomesticDuck (Concrete Class) -> Rubber Duck (Concrete class) *breaks interface segregation principle But in Vending Machine, all are the valid operations of a Vending Machine Interface, Vending Machine can do all operations, just it depend upon the state, but say in future we can extend and allow some operation in existing state right. Hope it clarifies. Yes one improvement we can do is instead of interface we can take abstract class and all the throw exception repetition we can avoid
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
Mock Low Level System Design Interview with Qualcomm Sr. Engineer - Design Meeting Scheduler
37:23
System Design: Concurrency Control in Distributed System | Optimistic & Pessimistic Concurrency Lock
1:04:45
18. Design CHESS GAME, LLD Mock Interview | Low Level Design Coding Interview Question
1:07:24
Concept && Coding - by Shrayansh
Рет қаралды 44 М.
Beginner System Design Interview: Design Bitly w/ a Ex-Meta Staff Engineer
59:30
Hello Interview - SWE Interview Preparation
Рет қаралды 39 М.
19. Design File System using Composite Design Pattern | Low Level Design Interview Question | LLD
21:30
3. Observer Design Pattern Explanation, Walmart Design Interview Question, 2022 | LLD System Design
34:34
State Pattern - Design Patterns (ep 17)
1:20:30
Christopher Okhravi
Рет қаралды 155 М.