Collaboration Diagram - Example

Self-service machine again will be target for this example. In previous example (See, Sequence Diagram - Example) the sequence diagram for this system was built. This is good time to try the ways of converting sequences into collaboration diagrams.

The best-case scenario consists of several steps:

1 The customer inserts money in the machine and makes selection of one or more product(s) present in the machine.
2 When the register gets the money (in this case customer puts the correct amount of money, and there is always a product in the selected brand), the selected product is delivered to the dispenser.
3 The dispenser delivers the product to the front of the machine, and the customer gets that product.

collaborationDiagram1.GIF (1892 bytes)

But when we examined this machine and its work in detail, new scenarios were introduced: incorrect-amount-of-money and out-of-product scenario. While building the sequence diagrams, conditions were introduced to display the work of the machine. Here conditions will be used too.

You put the condition inside a pair of square brackets, and the condition precedes the message-label. The important thing is to coordinate the conditions with the numbering. When you're modeling if statement there are two possible conditions. Messages for these conditions have a same number, and you add a decimal point and another number. This is called nesting.

In out-of-product scenario, the machine has to display an out of product message, and prompt the customer for another product or return the money back. If customer makes another selection this process must be repeated. Also a correct-amount-of-money scenario may be introduced. Collaboration diagram for this case is shown on the picture:

collaborationDiagram2.GIF (3582 bytes)

As you can see, from this picture two possible scenarios may happen. Out-of-product and Product-in are that two possibilities. If we assume that this happened after message 1:add(input,selection), the number for this messages will be 2, and we add 1 for the Product-in and 2 for the out-of-product scenarios, after the decimal point.

What happens when the machine doesn't have the correct change? The machine has to display an out of change message, return the money, and prompt the customer for the correct change. In effect, the transaction is over. When the machine has the correct change, it returns the change to the customer and delivers selected product.
Two branches that are produced from nesting process are numbered with 2.1 and 2.2. And three possibilities in condition-message 3 will be:3.1, 3.2 and 3.3. Collaboration diagram is shown on the following picture:

collaborationDiagram3.GIF (3334 bytes)

That's all for this example, and for this day. All you have to do now is answering the questions given in Questions & Answers and Workshop part from this day. Next day will introduce to you the last three UML diagrams.