Collaboration diagram for the use case

Collaboration diagrams provide another level of detail of the use case realization. We now know that sequence and collaboration diagrams are semantically the same, as they represent the interaction between the same elements, but the focus of the interaction is different. In the sequence diagram, the focus is on the order in time that messages are sent whereas in a collaboration diagram, the focus is on the object. Figure 8-5 shows the collaboration diagram for the Start Simulation use case.

Gardening Collaboration Diagram
Figure 8-5. Collaboration diagram for the use case Start Simulation.

As shown in Figure 8-5, object soil receives messages 3, 6, 11, and 14 from object simulator, message 9 from object plant and sends message 12 to object weather. Therefore, object soil should be provided with the appropriate behavior in order to respond to the received messages. Similarly, object plant receives messages 2, 5, 8, and 13 from object simulator and sends message 9 to object soil and message 10 to object weather. Therefore, object plant should be provided with the appropriate behavior to respond to messages it receives.

As shown in Figure 8-5, a collaboration diagram helps one to understand the kind of behavior objects should provided to be able to successfully dialog with each other to achieve the required functionality. Figure 8-6 shows the behavior defined for class Soil, defined by analyzing the collaboration diagram. According to the collaboration diagram, class Soil should respond to messages calculateRate, integrate, initialize, and create. For the moment, we do not have enough information to define the attributes of the class Soil, as we are focused on defining its behavior. Once we know the kind of behavior class Soil should provide, then the appropriate attributes will be added to its class definition.

According to the collaboration diagram, Simulator receives messages 1 and 15 from the user; therefore, its class definition should include methods named simulate and getSimulationResults. In the same way, we will define the behavior of class Plant as shown in Figure 8-7 and of class Weather shown in Figure 8-8.

Soil

^calculateRateQ ^integrate(} %iitialize() %reate()

^getWaterStressf)

Figure 8-6. The definition of behavior for class Soil.

Plant

^calculateRateQ

^integrateQ ^initializeQ

^ereateQ

Figure 8-7. The definition of behavior for class Plant.

Weather

♦getWeatheiOataQ

^initiai ize() ^c reateQ

Figure 8-8. The definition of behavior for class Weather.

0 0

Post a comment