20.4. Creating Methods from Interaction Diagrams
The sequence of the messages in an interaction diagram translates to a series of statements in the method definitions. The enterItem interaction diagram in Figure 20.2 illustrates the Java definition of the enterItem method. For this example, we will explore the implementation of the Register and its enterItem method. A Java definition of the Register class is shown in Figure 20.3.
Figure 20.2. The enterItem interaction diagram.
[View full size image]
Message 1:
public void enterItem(ItemID itemID, int qty)
A getProductDescription message is sent to the ProductCatalog to retrieve a ProductDescription .
Message 2:
ProductDescription desc = catalog.getProductDescription(itemID);
The makeLineItem message is sent to the Sale .
In summary, each sequenced message within a method, as shown on the interaction diagram, is mapped to a statement in the Java method.The complete enterItem method and its relationship to the interaction diagram is shown in Figure 20.4.
currentSale.makeLineItem(desc, qty);
The Register.enterItem Method
Figure 20.3. The Register class.
[View full size image]