![]() ![]() ![]() This is easier because of a limited number of states and not many state transitions but in a more real-world scenario, a state design pattern is better as it uses Polymorphism and removes the logic we have put inside the if-else block. Though, In our solution, I have not used the state design pattern but have just coded the solution with an if-else block. Vending machine behaves differently in different states like return a product if the machine is not empty, otherwise, it just returns coins, so it ideally fits in the state design pattern. As I said, there are multiple ways to design a Vending machine in Java, for example, you could have easily used state design patterns to implement a vending machine, in fact, it's one of the best examples of State design patterns. In the first part, we have discussed the problem statement and the solution itself, but unit testing and design document were still pending, which we'll see in this article. This is the second part of the Java tutorial to show how to design Vending Machine in Java. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |