Home > Articles > Software Development & Management > UML

  • Print
  • + Share This
This chapter is from the book 20.4 Creating Methods from Interaction Diagrams

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.

The enterItem message is sent to a Register instance; therefore, the enterItem method is defined in class Register.

public void enterItem(ItemID itemID, int qty)

Message 1: A getProductDescription message is sent to the ProductCatalog to retrieve a ProductDescription.

ProductDescription desc = catalog.getProductDescription(itemID);

Message 2: The makeLineItem message is sent to the Sale.

currentSale.makeLineItem(desc, qty);

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.

The Register.enterItem Method

Figure 20.3 The Register class.

Figure 20.4 The enterItem method.

  • + Share This
  • 🔖 Save To Your Account