CPS 108: Coffee Machine Design Problem

Spring 1999

Due at the end of class.

Form groups of size four or five persons. You may not work alone! You should start this group activity by introducing each member of the group. You may also want to choose one (or two) person(s) to write down the group's discussion as you go.

There are three parts to this activity:

What is "Design"?

If you have done an object-oriented design, how do you describe it to another person? What do you talk about or show, to convey your design? While your code is the ultimate resource to describe a design it is often not sufficient to convey your design accurately and quickly. Instead, you need a more concise way to present your design. A good design presentation will consist of the following things:
  1. The name of the key components, or things, in the system.
  2. The purpose, basic function, or main responsibility of each thing.
  3. A drawing of the key communication paths between them.
  4. A list of the services provided.
Of the four design elements, the brief "responsibility statement" is the most important. It tells an experienced person what will be included and what will be excluded from the data and behavior for the component. Then communication channel summaries show the collaborations between the things and the traffic patterns within the system. From this "map", purpose plus collaborations, an experienced person can reasonably find her way to interesting parts of your design.

For this exercise, you are going to use CRC cards to describe your design. A CRC card is a small piece of paper that lists the Class, its Responsibilities, and its Collaborators. The first describes its name and purpose (briefly). Next, its responsibilities (or methods). And finally, those classes that it collaborates with to complete its responsibilities. A single CRC card should be made for each class in your system.

The Coffee Machine Problem

You are a member of a group of contractors who just won a bid to design a custom coffee vending machine for the employees of Acme Fijet Works to use. Arnold, the owner of Acme Fijet Works, like the common software designer, eschews standard solutions. He wants his own, custom design. He is, however, a cheapskate. Arnold tells us he wants a simple machine. All he wants is a machine that serves coffee for 35 cents, with or without sugar and creamer. That's all. He expects us to be able to put this little machine together quickly and for little cost.

We get together and decide there will be a coin slot and coin return, coin return button, and four other buttons: black, white, black with sugar, white with sugar.

Now, design the machine using objects. What are the components, what are their responsibilities, how do they work together to deliver the simple service: give coffee for 35 cents?

Use Cases

Test your design against Kim's test scenarios.
  1. Kim puts in a quarter and then selects a coffee.
  2. Kim puts two quarters in and then selects a coffee.
  3. Kim puts in a quarter, then pushes the coin return lever.
  4. Kim puts in a two quarters, then walks away from the machine and forgets to come back.
  5. Kim buys two coffees, white with sugar. The sugar dispenser runs out of sugar after the first.
For each of these scenarios, each person in the group should "be" one or more classes in your design. This means you should take the CRC card representing your card and try to act like that class should act during program execution. In playing this role, it is important to be extremely literal in your interpretation of the class' responsibilities. One good way to "get into character" is to pretend that your class is a company that is trying to be as profitable as possible. To be profitable, the company must be as accomodating as possible to its clients (collaborators) while at the same time doing as little as possible (i.e., delegating work to other companies (classes)).

When you have successfully completed a scenario to your group's satisfaction, draw the interactions of your classes on a separate piece of paper. Your diagram does not have to be fancy, but should show which class called what to complete the scenario.

While working through these scenarios, it may be helpful to keep the following questions in mind: