The Unified Modeling Language User Guide SECOND EDITION [Electronic resources]

Grady Booch, James Rumbaugh, Ivar Jacobson

نسخه متنی -صفحه : 215/ 24
نمايش فراداده

Mechanisms

The hardest part of mastering a library as rich as Java's is learning how its parts work together. For example, how does HelloWorld's paint operation get invoked? What operations must you use if you want to change the behavior of this applet, such as making it print the string in a different color? To answer these and other questions, you must have a conceptual model of the way these classes work together dynamically.

Patterns and frameworks are discussed in Chapter 29 .

Studying the Java library reveals that HelloWorld's paint operation is inherited from Component. This still begs the question of how this operation is invoked. The answer is that paint is called as part of running the thread that encloses the applet, as Figure 3-5 illustrates.

Figure 3-5. Painting Mechanism

Processes and threads are discussed in Chapter 23 .

This figure shows the collaboration of several objects, including one instance of the class HelloWorld. The other objects are a part of the Java environment, so, for the most part, they live in the background of the applets you create. This shows a collaboration among objects that can be applied many times. Each column shows a role in the collaboration, that is, a part that can be played by a different object in each execution. In the UML, roles are represented just like classes, except they have both role names and types. The middle two roles in this diagram are anonymous, because their types are enough to identify them within the collaboration (but the colon and the absence of an underline mark them as roles). The initial THRead is called root, and the HelloWorld role has the name target known by the ComponentPeer role.

Instances are discussed in Chapter 13 .

You can model the ordering of events using a sequence diagram, as in Figure 3-5. Here, the sequence begins by running the Thread object, which in turn calls the Toolkit's run operation. The Toolkit object then calls one of its own operations (callbackLoop), which then calls the ComponentPeer's handleExpose operation. The ComponentPeer object then calls its target's paint operation. The ComponentPeer object assumes that its target is a Component, but in this case the target is actually a child of Component (namely, HelloWorld), so HelloWorld's paint operation is dispatched polymorphically.

Sequence diagrams are discussed in Chapter 19 .