Creating Methods from Interaction Diagrams - UML

The sequence of the messages in an interaction diagram translates to a series of statements in the method definitions. The enterltem interaction diagram in Figure illustrates the Java definition of the enterltem method. For this example, we will explore the implementation of the Register and its enterltem method. A Java definition of the Register class is shown in Figure.

Figure 20.2 The enterltem interaction diagram

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

public void enterltem (ItemIDitemID, intqty)

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

ProductDescriptiondesc = catalog.getProductDescription (itemID);

Message 2: The makeLineltem 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 enterltem method and its relationship to the interaction diagram is shown in Figure.

The Register.enterltemMethqd

Figure 20.3 The Register class

Figure 20.4 The enterltem method

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

UML Topics