Methods and the UML Sequence DiagramThe UML overview in Chapter 1, "Object-Oriented Programming," introduced the practice of using sequence diagrams to depict method calls between objects, which can be thought of as message passing. Figure 4.1 shows a sequence diagram for a simplified scenario for withdrawing a sum of money from a bank account. Here, the actor in the system sends a message to the AccountController that then interacts with an Account and an AccountTransaction to satisfy the request. Figure 4.1. A sequence diagram depicts method calls between objects.
In a formal design process, using an approach like this is precisely how the set of methods you need to implement for a class gets defined. If you know that a system must support a withdrawal operation, you can focus on the classes that will be involved and the required interaction between their instances. This allows you to discover the methods that are needed and eventually specify their exact signatures. From a design standpoint, the functionality introduced in this chapter relating to return types and parameter lists is the most important. After you move into implementation on the basis of the methods discovered in your sequence diagrams, other factors such as the access specifiers and modifiers associated with your methods become significant. |