14

I wanted to know what are the steps that I should follow to approach problems like design a vending machine and come up with a number of design documents (like use case, sequence diagram, class diagram). Is there any source/link that I can read where it talks about how to go step by step.

Thanks.

  • Jesse Liberty wrote a good book on this: http://www.amazon.com/Beginning-Object-Oriented-Analysis-Design-C/dp/1861001339 – Robert Jul 14 '09 at 19:33
  • 11
    It probably is homework, but hes not asking for the use cases to be drawn out for him. He just needs a push in the right direction. – Brandon Jul 14 '09 at 19:35
  • 2
    Cmon, everyone needs help with homework sometimes... – Daniel F. Thornton Jul 14 '09 at 19:37
  • @Brandon: He's asking for a step-by-step instructions without any sign he has tried to think about the problem on his own. If someone states the problem, shows what they have so far, and asks for a push in the right direction, I don't mind answering one bit. This guys sounds like he's basically asking SO to do his homework, without any effort on his part, and that isn't helpful to anyone, not in the long run. @ebaccount: Sorry if that's not your intent, but that's how I see it from here. – William Brendel Jul 14 '09 at 19:44
  • 3
    He isn't asking for an answer, just the approach. Looks like a homework request from someone looking to learn. – sal Jul 14 '09 at 19:44
  • 1
    @William Brendel I think "step by step" means he is looking for the steps to solve the problem, not the solution. – sal Jul 14 '09 at 19:46
  • 1
    I have to agree with sal. I read that question and took it like he wanted to know the proper procedure to solve this problem, not that he wanted the answer. – Brandon Jul 14 '09 at 19:49
  • 1
    I certainly do not need the answer of this particular problem. I need the right way of designing a software from the scratch. Vending machine is just an example, it could be any instant of design problem. –  Jul 14 '09 at 20:12

9 Answers9

18

I'm not sure if theres any universally accepted set of steps, but the easiest thing to do is just break down each and every step as far as you can go.

  1. Start with the major actions (putting in money, pressing a selection, receiving drink)
  2. Continue decomposing every action into smaller actions and responses until it becomes almost trivial. So for putting in money, you'd have to know how much was being put in, the total that was put in, the amount to be displayed, etc.
  3. Think of any scenarios where your actions would no longer be valid (you push a selection and the machine is empty), and how you would deal with it. (return their money, prompt for another choice, etc.)
  4. Assign the actions and responses to the actors and to the system. Who puts in the money, who keeps track of the running total?

Then you can base your sequence diagrams and class diagram off of what you've come up with.

Brandon
  • 68,708
  • 30
  • 194
  • 223
4

Well, a vending machine is basically a state machine.

I would decide what the valid inputs would be (coins and bills?) and what the outputs would be.

What are the likely outcomes from a user walking up to the machine. What problems might occur? (too much money, too little money) How would they be handled? (dispense change, dispense refund)

Lastly, write out the things that you would need to handle the use cases. Your nouns are likely Classes. Your verbs are likely methods that belong to those classes.

sal
  • 23,373
  • 15
  • 66
  • 85
3

Broadly, think about what objects are involved in a vending machine:

  • VendingMachine - possibly an abstract class
  • DrinkMachine, SnackMachine, and classes extending VendingMachine
  • VendingProduct - an abstract class?
  • Drink, other classes extending VendingProduct
  • Coke, other classes extending Drink
  • &c, &c.

But I'm sure you can figure that out pretty easily. The nuts and bolts of the machine will take place in some kind of utility class, with methods to accept bills and coins, calculate change, etc.

Further reading:

  • Here is a good article on beginning an OOP design, by Allen Holub.
  • Here is the beginning of a Coffee Vending Machine design using OOP.
Daniel F. Thornton
  • 3,687
  • 2
  • 28
  • 41
  • The first link is dead, can you give another one for that? – Mohit Dec 14 '14 at 14:25
  • Updated with archived version: https://web.archive.org/web/20090228114745/http://www.ibm.com/developerworks/webservices/library/ws-oo-design1/ – Daniel F. Thornton Dec 14 '14 at 18:10
  • first link is also dead. here's the new address: http://www.maheshsubramaniya.com/article/object-oriented-programming-encapsulation-is-not-just-hiding-data.html – Yar Dec 04 '16 at 00:41
3

I assume you've seen this link already.

Don't think about code (classes, &c.) first. Think about use cases and functional requirements. What functionality is the vending machine supposed to provide? How are the users expected to interact with it? How about the maintainers? Try not to confuse implementation details from high-level needs while doing this.

Then, depending on what type of class project this is for, think about the non-functional requirements. What's the most important attribute: speed, reliability, ease of maintenance, adaptability to new situations, security, ...? There are other possibilities. These aren't binary, yes/no answers, think more in terms of ranges and minimum standards vs. optimal goals. Note, "optimal" depends on the perspective of the stakeholder in question. Ease of use and security are often in conflict, so you have to figure out which is more important.

After that, you can go back to your use cases, and see how they're impacted by your non-functional requirements. This is where negotiation happens with your client, who in this case is probably you. Do you have to sacrifice features in order to meet some other goal? For each feature, what is the risk vs. the reward? Easy to implement features which provide high value are great. Difficult to implement (due to constraints) features which only add small value should clearly be prioritized last. The other two combinations require careful thought.

Then you can start designing the machine.

There are tons of different diagrams you can use to either help you visualize the problem, or explain your proposed solution to others.

Michael H.
  • 862
  • 1
  • 7
  • 14
1

start by defining "vendor machine":

A vendor machine is a machine that .....

presto! there's your requirements.

Javier
  • 60,510
  • 8
  • 78
  • 126
1

To Approach such problems

  1. Identify Requirements, functionality usecase

  2. Break down these requirements into tasks trivial and basic

  3. Identify challanges and issues that user may face , and from system perspective . all invalid scnearios. also requirement like performance , security , reliability.
  4. Identify solution for all the challanges and issues listed down earlier
  5. mark all nouns as classes and verbs and action as method . also identify public interfaces for the class based on how classes will interact with each other and with external actors
  6. based on the scenario and problem statement try applying any design pattern if you know them . (just a add on to show your knowledge of design patterns )
  7. present your design with the help of class diagram use case diagrams etc.

and definately ask a lot of questions to clear the requirements

1

For some problems (like vending machine), it can be tackled by object oriented design with State Machine.

The initial status is idle and goes to typing if start typing, it allows clear, cancel and submit when typing item row and column number, then it takes care of payment after submit the item row and column number, finally it will pop out the item if paid successfully, otherwise pay again.

For classes in vending machine, there should be some buttons to indicate row (A, B, C) and column(1, 2, 3) number, some buttons to clear, cancel or submit row and column numbers, some slots to accept payment (cash, coin, credit/debit card), some slots to hold items (drink, snack, etc.).

Refer to the blog

Yao Li
  • 2,071
  • 1
  • 25
  • 24
0

These thoughts may help:

From an interface perspective define inputs, outputs, expected conditions, error conditions.

Decide how good it needs to look.

How long does it need to operate (service life).

How often does it need restocking?

LG_PDX
  • 834
  • 8
  • 12
0

There isn't only one right way to design all software from scratch!

There are probably dozens of different approaches ranging from very little upfront design such as in Evolutionary Design to Big Up Front Design which was written up in August 2005 on JoelOnSoftware. There are probably more than a few inbetween methods that have their place so it depends on what development methodology you want to use as some may require more upfront design like in a Waterfall approach compared to something more Agile where requirements can change regularly and this doesn't cause a lot of problems or at least that is the theory.

JB King
  • 11,860
  • 4
  • 38
  • 49