Presentation is loading. Please wait.

Presentation is loading. Please wait.

60-322 Object-Oriented Analysis and Design Feb 11, 2009.

Similar presentations


Presentation on theme: "60-322 Object-Oriented Analysis and Design Feb 11, 2009."— Presentation transcript:

1 60-322 Object-Oriented Analysis and Design Feb 11, 2009

2 2 We were discussing Object Design. There are two kinds of object models: dynamic and static. What's important is knowing how to think and design in objects, and apply object design best-practice patterns, which is a very different and much more valuable skill than knowing UML notation. The UML includes interaction diagrams to illustrate how objects interact via messages. They are used for dynamic object modeling. There are two common types: – sequence and communication interaction diagrams. Last lecture covered….

3 Feb 11, 2009 3 Diagram Frames in UML Sequence Diagram Basic Sequence Diagram Notation To support conditional and looping constructs (among many other things), the UML uses frames. Frames are regions or fragments of the diagrams; they have an operator or label (such as loop) and a guard(conditional clause).

4 Feb 11, 2009 4 Diagram Frames in UML Sequence Diagram Basic Sequence Diagram Notation

5 Feb 11, 2009 5 Diagram Frames in UML Sequence Diagram Basic Sequence Diagram Notation

6 Feb 11, 2009 6 Diagram Frames in UML Sequence Diagram Basic Sequence Diagram Notation

7 Feb 11, 2009 7 Diagram Frames in UML Sequence Diagram Basic Sequence Diagram Notation

8 Feb 11, 2009 8 How to Relate Interaction Diagrams Basic Sequence Diagram Notation

9 Feb 11, 2009 9 How to Relate Interaction Diagrams Basic Sequence Diagram Notation An interaction occurrence (also called an interaction use) is a reference to an interaction within another interaction. It is useful, for example, when you want to simplify a diagram and factor out a portion into another diagram, or there is a reusable interaction occurrence. UML tools take advantage of them, because of their usefulness in relating and linking diagrams.

10 Feb 11, 2009 10 How to Relate Interaction Diagrams Basic Sequence Diagram Notation They are created with two related frames: – a frame around an entire sequence diagram, labeled with the tag sd and a name, such as AuthenticateUser. – a frame tagged ref, called a reference, that refers to another named sequence diagram; it is the actual interaction occurrence. Guideline: – Any sequence diagram can be surrounded with an sd frame, to name it. Frame and name one when you want to refer to it using a ref frame

11 Feb 11, 2009 11 Message to Classes to Invoke Static Methods Basic Sequence Diagram Notation You can show class or static method calls by using a lifeline box label that indicates the receiving object is a class, or more precisely, an instance of a metaclass

12 Feb 11, 2009 12 Message to Classes to Invoke Static Methods Basic Sequence Diagram Notation

13 Feb 11, 2009 13 Polymorphic Messages and Cases Basic Sequence Diagram Notation Polymorphism is fundamental to OO design. How to show it in a sequence diagram? One approach is to use multiple sequence diagrams - one that shows the polymorphic message to the abstract super class or interface object, and then separate sequence diagrams detailing each polymorphic case, each starting with a found polymorphic message.

14 Feb 11, 2009 14 Polymorphic Messages and Cases Basic Sequence Diagram Notation

15 Feb 11, 2009 15 Ch 15.5 Basic Communication Diagram Notation - Link A link is a connection path between two objects; it indicates some form of navigation and visibility between the objects is possible. link More formally, a link is an instance of an association. For example, there is a link - or path of navigation - from a Register to a Sale, along which messages may flow, such as the makePayment message.

16 Feb 11, 2009 16 Message Each message between objects is represented with a message expression and small arrow indicating the direction of the message. Many messages may flow along this link. A sequence number is added to show the sequential order of messages in the current thread of control. Don't number the starting message. It's legal to do so, but simplifies the overall numbering if you don't.

17 Feb 11, 2009 17 Message to “self” or “this” A message can be sent from an object to itself. This is illustrated by a link to itself, with messages flowing along the link.

18 Feb 11, 2009 18 Creation of Instance The convention in the UML is to use a message named create for this purpose (some use new). If another (less obvious) message name is used, the message may be annotated with a UML stereotype, like so: «create». The create message may include parameters, indicating the passing of initial values. – This indicates, for example, a constructor call with parameters in Java. – Furthermore, the UML tagged value {new} may optionally be added to the lifeline box to highlight the creation. Tagged values are a flexible extension mechanism in the UML to add semantically meaningful information to a UML element.

19 Feb 11, 2009 19 1:create(cashier) :Register:Sale create message,with optional initializing parameters.This will normally be interpreted as a constructor call. «create» 1:make(cashier) :Register:Sale if an unobvious creation message name is used,the message may be stereotyped for clarity 1:create(cashier) :Register:Sale{new} Three ways to show creation in a communication diagram The convention in the UML is to use a message named create for this purpose (some use new). If another (less obvious) message name is used, the message may be annotated with a UML stereotype, like so: «create».

20 Feb 11, 2009 20 Message Numbering The order of messages is illustrated with sequence numbers. The numbering scheme is: – The first message is not numbered. Thus, msg1 is unnumbered. – The order and nesting of subsequent messages is shown with a legal numbering scheme in which nested messages have a number appended to them. You denote nesting by prepending the incoming message number to the outgoing message number.

21 Feb 11, 2009 21 Message Numbering – A More Complex Case

22 Feb 11, 2009 22 Conditional Message You show a conditional message by following a sequence number with a conditional clause in square brackets, similar to an iteration clause. The message is only sent if the clause evaluates to true.

23 Feb 11, 2009 23 Mutually Exclusive Conditional Paths

24 Feb 11, 2009 24 Iteration or Looping

25 Feb 11, 2009 25 Iteration or Looping

26 Feb 11, 2009 26 Message to Classes to Invoke Static Methods Basic Sequence Diagram Notation You can show class or static method calls by using a lifeline box label that indicates the receiving object is a class, or more precisely, an instance of a metaclass

27 Feb 11, 2009 27 Messages to a Classes to Invoke Static (Class) Methods – Communication Diagram 1:locs=getAvailableLocales :Foo «metaclass» Calendar doX message to class,or a static method call

28 Feb 11, 2009 28 Polymorphic Messages and Cases Basic Sequence Diagram Notation

29 Feb 11, 2009 29 Polymorphic Messages–Communication Diagram :Register authorizedoX :Payment{abstract} polymorphic message object in role of abstract superclass :DebitPayment authorize :Foo stop at this point– don’t show any further details for this message separate diagrams for each polymorphic concrete case doA doB :CreditPayment authorize :Bar doX

30 Feb 11, 2009 30 The UML includes class diagrams to illustrate classes, interfaces, and their associations. They are used for static object modeling. – We've already introduced and used this UML diagram while domain modeling, applying class diagrams in a conceptual perspective. This chapter summarizes more of the notation, irrespective of the perspective (conceptual or software). As with the prior interaction diagram chapter, this is a reference. – Subsequent chapters focus on a more important question: What are key principles in OO design? Those chapters apply UML interaction and class diagrams to help explain and demonstrate object design. Ch 16 UML Class Diagram

31 Feb 11, 2009 31 Ch 16 UML Class Diagram Much of the high-frequency class diagram notation can be summarized (and understood) in the figure below. Most elements in the figure are optional (e.g., +/- visibility, parameters, compartments). Modelers draw, show or hide them depending on context and the needs of the reader or UML tool.visibility

32 Feb 11, 2009 32 As we know, the same UML diagram can be used in multiple perspectives. In a conceptual perspective the class diagram can be used to visualize a domain model. For discussion, we also need a unique term to clarify when the class diagram is used in a software or design perspective. A common modeling term for this purpose is design class diagram (DCD). In the UP, the set of all DCDs form part of the Design Model. Other parts of the Design Model include UML interaction and package diagrams. Definition: Design Class Diagram

33 Feb 11, 2009 33 A UML classifier is "a model element that describes behavioral and structure features". Classifiers can also be specialized. They are a generalization of many of the elements of the UML, including classes, interfaces, use cases, and actors. In class diagrams, the two most common classifiers are regular classes and interfaces. Definition: Classifier

34 Feb 11, 2009 34 Attributes of a classifier (also called structural properties in the UML) are shown several ways: – attribute text notation, such as currentSale : Sale. – association line notation – both together Show UML Attributes: Attribute Text and Association Lines

35 Feb 11, 2009 35 Show UML Attributes: Attribute Text and Association Lines

36 Feb 11, 2009 36 The full format of the attribute text notation is: visibility name : type multiplicity = default {property-string} Also, the UML allows any other programming language syntax to be used for the attribute declaration. visibility marks include + (public), - (private), and so forth. visibility Guideline: Attributes are usually assumed private if no visibility is given. Show UML Attributes: Attribute Text and Association Lines

37 Feb 11, 2009 37 Notice in the previous figure that this attribute-as-association line has the following style: – a navigability arrow pointing from the source (Register) to target (Sale) object, indicating a Register object has an attribute of one Sale – a multiplicity at the target end, but not the source end – a rolename (currentSale) only at the target end to show the attribute name – no association name Show UML Attributes: Attribute Text and Association Lines

38 Feb 11, 2009 38 Guideline: When showing attributes-as- associations, follow this style in DCDs, which is suggested by the UML specification. Guideline: On the other hand, when using class diagrams for a domain model do show association names but avoid navigation arrows, as a domain model is not a software perspective. Show UML Attributes: Attribute Text and Association Lines

39 Feb 11, 2009 39 Guideline: Use the attribute text notation for data type objects and the association line notation for others. When to Use Attribute Text versus Association Lines for Attributes?

40 Feb 11, 2009 40 these different styles exist only in the UML surface notation; in code, they boil down to the same thing - the Register class will have three attributes. For example, in Java: public class Register { private int id; private Sale currentSale; private Store location; // … } When to Use Attribute Text versus Association Lines for Attributes?

41 Feb 11, 2009 41 The UML Notation for an Association End

42 Feb 11, 2009 42 The end of an association can have a navigability arrow. It can also include an optional rolename (officially, an association end name) to indicate the attribute name. The association end may also show a multiplicity value, such as '*' or '0..1'.multiplicity The rolename is used to indicate the attribute name The UML Notation for an Association End

43 Feb 11, 2009 43 A property string such as {ordered} or {ordered, List} is possible for an association end. {ordered} is a UML-defined keyword that implies the elements of the collection are ordered. Another related keyword is {unique}, implying a set of unique elements. The keyword {List} illustrates that the UML also supports user-defined keywords. One may define {List} to mean the collection attribute lineItems will be implemented with an object implementing the List interface The UML Notation for an Association End

44 Feb 11, 2009 44 Collection Attributes


Download ppt "60-322 Object-Oriented Analysis and Design Feb 11, 2009."

Similar presentations


Ads by Google