UML for Java Programmers Object Mentor, Inc. Copyright by Object Mentor, Inc All Rights Reserved Or How Uncle Bob uses UML.
2 The three modes of UML Conceptual Tied to human language. Specification A description of source code yet to be written. Implementation A description of source code that already exists.
3 Conceptual Tied to human language: “An Animal ISA Dog”
4 Hmmm…
5 Tied to human language
6 Models of the “Real World” Do not relate to software structure. Now it’s time for: Uncle Bob’s rant…. Human language is not the best foundation for software structure. A Circle ISA Ellipse.
7 A Circle ISA Ellipse
8 Specification and Implementation Are tied to code. Follow the same rules. Differ only in detail. Sometimes.
9 Example: public class TreeMap { TreeMapNode topNode = null; public void add(Comparable key, Object value) {…} public Object get(Comparable key) {…} } class TreeMapNode { private Comparable itsKey; private Object itsValue; private TreeMapNode nodes[] = new TreeMapNode[2]; public TreeMapNode(Comparable key, Object value) {…} public Object find(Comparable key) {…} public void add(Comparable key, Object value) {…} }
10 Here’s some UML for that.
11 Classes and Relationships. Rectangles represent classes, and arrows represent relationships.
12 Associations. In this diagram all the relationships are associations. Associations are simple data relationships in which one object holds a reference to, and invokes methods upon, the other.
13 Relationship Names. The name on an association maps to the name of the variable that holds the reference. public class TreeMap { TreeMapNode topNode = null; }
14 Multiplicity. A number next to an arrowhead typically shows the number of instances held by the relationship. If that number is greater than one then some kind of container, like an array, is implied. class TreeMapNode { private TreeMapNode nodes[] = new TreeMapNode[2]; }
15 Class Icons. Class icons can have more than one compartment. The top compartment always holds the name of the class. The other compartments describe functions and variables.
16 Interface. The «interface» notation means that Comparable is an interface.
17 Optional. Most of the notations shown are optional Uncle Bob is going to rant again…
18 >. But Uncle Bob, you didn’t talk about Aggregation or Composition. Rant….
19 Object Diagrams.
20 Freeze Frame. It shows a set of objects and relationships at a particular moment in the execution of the system. You can view it as a snapshot of memory.
21 Object Names are Underlined. the rectangle icons represent objects. You can tell that they are objects because their names are underlined.
22 Object : Class The name after the colon is the name of the class that the object belongs to.
23 Values. Note that the lower compartment of each object shows the value of that object’s itsKey variable.
24 Links. The relationships between the objects are called links, and are derived from the associations.
25 Sequence Diagrams. public void add(Comparable key,Object value){ if (topNode == null) topNode = new TreeMapNode(key, value); else topNode.add(key, value); }
26 Actor. The stick figure (actor) represents an unknown caller.
27 Lifelines. The dashed lines are lifelines, they show the lifetime of the objects they descend from.
28 Messages. The long arrows are messages sent between the objects.
29 Guards. The boolean expressions inside square brackets are called guards. They show which path is taken.
30 Construction. The message arrow that terminates on the TreeMapNode icon represents construction.
31 Data Tokens The little arrows with circles are called data tokens. They show any arguments or return values.
32 Activations. The skinny rectangle below TreeMap is called an activation. It depicts how much time the add method executes.
33 Collaboration Diagrams.
34 Same data as Sequence Diagrams. Collaboration diagrams make the relationships between the objects clear.
35 Links (again). The objects are connected by relationships called links. A link exists wherever one object can send a message to another.
36 Messages. Traveling over those links are the messages themselves. They are depicted as the smaller arrows.
37 Message Labels. The messages are labeled with the name of the message, its sequence number, and any guards that apply.
38 Sequence Numbers. The dot structure of the sequence number shows the calling hierarchy.
39 State Diagrams. A Subway Turnstile.
40 States. There are two states named Locked and Unlocked.
41 Events. Two events may be sent to the machine. The coin event means that the user has dropped a coin into the turnstile. The pass event means that the user has passed through the turnstile.
42 Transitions. The arrows are called transitions. They are labeled with the event that triggers the transition and the action that the transition performs.
43 Interpretation. If we are in the Locked state and we get a coin event, then we transition to the Unlocked state and we invoke the Unlock function. If we are in the Unlocked state and we get a pass event, then we transition to the Locked state and we invoke the Lock function. If we are in the Unlocked state and we get a coin event, then we stay in the Unlocked state and we call the Thankyou function. If we are in the Locked state and we get a pass event, then we stay in the Locked state and we call the Alarm function.
44 Sufficiency. The diagrams shown in this chapter are enough for most purposes. Most programmers could live without any more knowledge of UML that what is shown here.
45 Tools. Now ask me what I think about tools…..
46 Documentation.
47 Where to get this presentation.