s ravi chandran wrote:Okay, i need to understand this for now.
s ravi chandran wrote:is the role of topUp() to get the quantity to add items to a slot? or is it a replacement for add() ?
Junilu Lacar wrote:
s ravi chandran wrote:Okay, i need to understand this for now.
===============
| __ __ __ __ | ← one shelf
| __ __ __ __ |
| __ __ __ __ |
| __ __ __ __ |
===============
↑
one tray
Imagine you are looking at the front of the vending machine. One row is a shelf. One element in the row is a tray. Each tray will hold up to 8 pieces of one type of product.
s ravi chandran wrote:
I added these lines in my code
Junilu Lacar wrote:
s ravi chandran wrote:
I added these lines in my code
You're breaking TDD rules. You should wait until you have to refactor some code before you introduce a constant like this. Plus, skipped writing a failing test.![]()
s ravi chandran wrote:max product a shelf can handle will be max_slots_per_row * max_products_per_slot.
Junilu Lacar wrote:Then you write another test, make sure it fails, so you can triangulate the correct implementation of the topUp method.
Junilu Lacar wrote:This technique takes a lot of discipline and dedication to learn to do properly and effectively. You need to read up on refactoring. You need to read up on design principles. Search for Design Principles SOLID, SLAP, DRY. You need to recognize code smells. And you need to question EVERY small design choice you make and look at how it fits into the big picture.
I think I'll leave the rest to you as an exercise. Try to code it all out by yourself and we'll see what you come up with.
s ravi chandran wrote:
Junilu Lacar wrote:Then you write another test, make sure it fails, so you can triangulate the correct implementation of the topUp method.
like this?
Junilu Lacar wrote:I'm also going to work on it. I have the code up in GitHub:
main: https://github.com/jlacar/ranch-samples/tree/master/samples/src/main/java/com/coderanch/samples/design/vend
test: https://github.com/jlacar/ranch-samples/tree/master/samples/src/test/java/com/coderanch/samples/design/vend
Junilu Lacar wrote:I think I've reached a point where VendingMachine has all the functionality I believe it should have. As it turns out, VendingMachine itself only needs a couple of constructors and a few methods: isEmpty, fill, and dispense. As for other functionality like accepting money and making change, it seems like a different class is needed. Let me know when you are ready to continue the discussion.
. So, this won't work. I did take the product add logic from your method though. this line: what I was thinking was to give an option to the vendor to add any number of product to the slot. for which we would definitely have to add a condition to check product count exceeding max value. but i guess, your way is more precise, end target for each add or topUp is to fill the slot to max.topUp_should_fill_a_partially_empty_tray()
s ravi chandran wrote:I had added these two methods
s ravi chandran wrote:i had not refractored it. Copied it from previous methods which i had commented.. :-)
s ravi chandran wrote:i had added a logic like this before
s ravi chandran wrote:Yes, I guess, that will come with more understanding of application. Well, I did remove the logic later, as it was failing the partial fill case.
s ravi chandran wrote:If we are considering filling up slots with fixed number of products, then can we add one more test case for that?
Will this be okay?
I suppose that's fine. My preference to have a simpler version that doesn't need additional input is simply that, a preference. I think it does make for simpler code for that particular workflow though.s ravi chandran wrote:yes it was similar but I was adding the quantity as a parameter.
s ravi chandran wrote:My code is formatted, it is just after posting, the spaces and the tabs do the trick.
I had one question regarding the console option. if the user presses FILL PART, do we show him the current remaining quantity? or can he use the report option for that?
Junilu Lacar wrote:
s ravi chandran wrote:My code is formatted, it is just after posting, the spaces and the tabs do the trick.
Ok, I'll let it slide this time ...![]()
I had one question regarding the console option. if the user presses FILL PART, do we show him the current remaining quantity? or can he use the report option for that?
Well, put yourself in the guy's shoes. Does the remaining quantity really concern you when you're loading product into a tray? If it were me, it wouldn't. I just want to know how much product I need to fill up the tray. The report I print before loading up the machine has that other information anyway.
s ravi chandran wrote:so we do show the user the remaining quantity to be filled.. ?
Hey! Wanna see my flashlight? It looks like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|