|
Design vending machine in Java which vends Item based upon four denomination of coins and return coin if there is no Item.
It is not optimized.
It doesn't support multi threaded requests.
Ulf Dittmer wrote:"Better" in what sense?
It is not optimized.
Optimize for what? Why do you think it needs to be optimized?
It doesn't support multi threaded requests.
How do you wish to support concurrency? There are any number of ways to do that. In which way do you think your current approach does not?
s ravi chandran wrote:i can expand it to have a bunch of vending machines with each having a different set of items. each will be requested for an item for a user
Junilu Lacar wrote:
s ravi chandran wrote:i can expand it to have a bunch of vending machines with each having a different set of items. each will be requested for an item for a user
How do you propose to do that with your current design with VendingProduct as an enum? Add more enums? Is that a good design choice?
Think about this: In real life, how are vending machines set up? What does the guy who fills the vending machine have to do when he fills up the machine? What kind of user interface does the guy have so he can program the machine to know things it needs to know to sell products properly. How does the machine know when there are things to sell and when a slot is empty? How does the machine know how much to charge for each item? How does it know if enough money was dropped in? How does it know when it needs to give back change?
s ravi chandran wrote:Multi threading aspect is only being added for learning purpose, I will not be emulating everything as per real life scenario.
s ravi chandran wrote:I need to add more components to the design.
s ravi chandran wrote:Okay, well, I initially used enum to define items listed on the machine. As they won't change much over time, unless I am adding a new set of item range.
Junilu Lacar wrote:Why does your product price have a type of CurrencyDenomination? What if you had a product that you wanted to sell for $1.00? $1.25? $1.95? And how do you intend to calculate how much change you're going to give back to the customer?
Carey Brown wrote:ItemSlot.removeItem() should probably return a boolean to indicate if there was an item to remove.
Junilu Lacar wrote:I don't see a need to represent Customer in your program. A customer is an external entity and no information about a customer is needed for the machine to function. I'm not so sure about Item Selector. If it were me, I would have to write some test code to see what the code wants to do.
Where did your unit tests go? Right now, you are just adding code that you think you'll need rather than code that the tests tell you is needed. I find that Test-Driven Development and using tests to drive your design thinking results in better and more concise designs.
s ravi chandran wrote:my overall application ends up in a mess most of the time, in terms of understanding for other developers.
s ravi chandran wrote:Well, like i said in order to understand how TDD is helping in design, i should know what a good design is. Would you give an example for TDD if possible
Junilu Lacar wrote:I'm going to pause with the TDD example to give you a chance to ask questions and share some of your thoughts about where the design is going at this point. What do you think about the proposed API for adding products to sell from the vending machine? What do you think is the next test to write to show that the current implementation of the itemCount method has a bug?
. Now following the finding the bug sequence. I think itemCount should be backed by a list of items.2. As a vendor, I want to add new items to sell
s ravi chandran wrote: Does this look correct? I was actually thinking of a implementation for the slot objects, but i remembered TDD works with small steps at a time. So, just added these lines for now.
Junilu Lacar wrote:Don't write tests just because you can. Use tests to flesh out your design. We aren't even done with the functionality to add products yet so it's not the right time to move to removing products. The new test should help triangulate the correct implementation of adding products. You have a passing test that adds a specific amount right now and the implementation bug is that it only works for that particular case. We need to introduce another case for adding products where the implementation will obviously fail to produce the correct results.
Junilu Lacar wrote:Here's another point to ponder: is itemCount even appropriate to introduce at this time? Is there something simpler that we can do to verify the add method? This question goes back to design focus. Try not to work on too many aspects of the design at once. The fewer unpolished facets of the design you have to deal with at one time, the simpler it is to make decisions and mange complexity.
s ravi chandran wrote:
We can have add return true as a response for a successful add and false for a failure in add product. that way, we will only deal with add and not the products.
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|