Use case diagrams Class diagrams Sequence diagrams Activity

  • Slides: 45
Download presentation
¨ ¨ ¨ Use case diagrams Class diagrams Sequence diagrams Activity diagrams State diagrams

¨ ¨ ¨ Use case diagrams Class diagrams Sequence diagrams Activity diagrams State diagrams Most Frequently Used (optional) Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 1

Behavioral Diagrams: captures dynamic aspects ¨ Use case diagram w Organizes the behavior of

Behavioral Diagrams: captures dynamic aspects ¨ Use case diagram w Organizes the behavior of the system ¨ Sequence diagram w Focuses on time ordering of messages ¨ Communication diagram w Focuses on structural organization of objects that send and receive messages ¨ Activity diagram w Focuses on the flow of control from Activity to Activity. ¨ State diagram w Describe the dynamic behavior of an individual object w Focuses on changing state of a system driven by Events. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2

UML first pass: Use case diagrams Use Case Actor Use case diagrams represent the

UML first pass: Use case diagrams Use Case Actor Use case diagrams represent the functionality of the system from user’s point of view Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3

UML first pass: Class diagrams Association Class Multiplicity 2 Push. Button Simple. Watch 1

UML first pass: Class diagrams Association Class Multiplicity 2 Push. Button Simple. Watch 1 1 Display 1 1 Battery 1 Time Class diagrams represent the structure of the system Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4

UML first pass: Class diagrams represent the structure of the system Association Class Multiplicity

UML first pass: Class diagrams represent the structure of the system Association Class Multiplicity 1 2 Push. Button state push() release() Attribute Bernd Bruegge & Allen H. Dutoit Watch 1 1 1 LCDDisplay blink. Idx blink. Seconds() blink. Minutes() blink. Hours() stop. Blinking() referesh() Battery Load Object-Oriented Software Engineering: Using UML, Patterns, and Java 1 Time Now Operations 5

UML first pass: Sequence diagram Actor Message : Watch. User Object : Watch press.

UML first pass: Sequence diagram Actor Message : Watch. User Object : Watch press. Button 1() press. Button 2() Lifeline : LCDDisplay : Time blink. Hours() blink. Minutes() increment. Minutes() refresh() press. Button 1 and 2() commit. New. Time() Activation stop. Blinking() Sequence diagrams represent the behavior of a system as messages (“interactions”) between different objects Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6

UML Use Case Diagrams Used during requirements elicitation and analysis to represent external behavior

UML Use Case Diagrams Used during requirements elicitation and analysis to represent external behavior (“visible from the outside of the system”) An Actor represents a role, that is, a type of user of the system Passenger A use case represents a class of functionality provided by the system Purchase. Ticket Bernd Bruegge & Allen H. Dutoit Use case model: The set of all use cases that completely describe the functionality of the system. Object-Oriented Software Engineering: Using UML, Patterns, and Java 7

Actors ¨ An actor is a model for an external entity which interacts (communicates)

Actors ¨ An actor is a model for an external entity which interacts (communicates) with the system: w User w External system (Another system) w Physical environment (e. g. Weather) Passenger Name Bernd Bruegge & Allen H. Dutoit ¨ An actor has a unique name and an optional description Optional ¨ Examples: Description w Passenger: A person in the train w GPS satellite: An external system that provides the system with GPS coordinates. Object-Oriented Software Engineering: Using UML, Patterns, and Java 8

Use Case Purchase. Ticket Bernd Bruegge & Allen H. Dutoit • A use case

Use Case Purchase. Ticket Bernd Bruegge & Allen H. Dutoit • A use case represents a class of functionality provided by the system • Use cases can be described textually, with a focus on the event flow between actor and system • The textual use case description consists of 6 parts: 1. 2. 3. 4. 5. 6. Unique name Participating actors Entry conditions Exit conditions Flow of events Special requirements. Object-Oriented Software Engineering: Using UML, Patterns, and Java 9

Textual Use Case Description Example Passenger 1. Name: Purchase ticket 2. Participating actor: Passenger

Textual Use Case Description Example Passenger 1. Name: Purchase ticket 2. Participating actor: Passenger 3. Entry condition: ¨ Passenger stands in front of ticket distributor ¨ Passenger has sufficient money to purchase ticket Purchase. Ticket 5. Flow of events: 1. Passenger selects the number of zones to be traveled 2. Ticket Distributor displays the amount due 3. Passenger inserts money, at least the amount due 4. Ticket Distributor returns change 5. Ticket Distributor issues ticket 6. Special requirements: None. 4. Exit condition: ¨ Passenger has ticket Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10

Uses Cases can be related ¨ Extends Relationship w To represent seldom invoked use

Uses Cases can be related ¨ Extends Relationship w To represent seldom invoked use cases or exceptional functionality ¨ Includes Relationship w To represent functional behavior common to more than one use case. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11

The <<extends>> Relationship ¨ ¨ Passenger ¨ ¨ Purchase. Ticket <<extends>> relationships model exceptional

The <<extends>> Relationship ¨ ¨ Passenger ¨ ¨ Purchase. Ticket <<extends>> relationships model exceptional or seldom invoked cases The exceptional event flows are factored out of the main event flow for clarity The direction of an <<extends>> relationship is to the extended use case Use cases representing exceptional flows can extend more than one use case. <<extends>> Out. Of. Order <<extends>> Cancel Bernd Bruegge & Allen H. Dutoit Time. Out No. Change Object-Oriented Software Engineering: Using UML, Patterns, and Java 12

The <<includes>> Relationship ¨ ¨ Passenger Purchase. Multi. Card ¨ Purchase. Single. Ticket <<includes>>

The <<includes>> Relationship ¨ ¨ Passenger Purchase. Multi. Card ¨ Purchase. Single. Ticket <<includes>> <<extends>> Collect. Money No. Change Bernd Bruegge & Allen H. Dutoit <<extends>> Cancel <<includes>> relationship represents common functionality needed in more than one use case <<includes>> behavior is factored out for reuse, not because it is an exception The direction of a <<includes>> relationship is to the using use case (unlike the direction of the <<extends>> relationship). <<extends>> Cancel Object-Oriented Software Engineering: Using UML, Patterns, and Java 13

Object Modeling in Practice Foo Amount Customer. Id Deposit() Withdraw() Get. Balance() Class Identification:

Object Modeling in Practice Foo Amount Customer. Id Deposit() Withdraw() Get. Balance() Class Identification: Name of Class, Attributes and Methods Is Foo the right name? Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14

Object Modeling in Practice: Brainstorming Foo “Dada” Amount Customer. Id Deposit() Withdraw() Get. Balance()

Object Modeling in Practice: Brainstorming Foo “Dada” Amount Customer. Id Deposit() Withdraw() Get. Balance() Account Amount Customer. Id Is Foo the right name? Bernd Bruegge & Allen H. Dutoit Deposit() Withdraw() Get. Balance() Object-Oriented Software Engineering: Using UML, Patterns, and Java 15

Object Modeling in Practice: More classes Account Amount Account. Id Customer. Id Bank Deposit()

Object Modeling in Practice: More classes Account Amount Account. Id Customer. Id Bank Deposit() Withdraw() Get. Balance() Name Customer. Id 1) Find New Classes 2) Review Names, Attributes and Methods Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16

Object Modeling in Practice: Associations Account * ? Bank has Name Amount Account. Id

Object Modeling in Practice: Associations Account * ? Bank has Name Amount Account. Id Customer. Id Account. I d Deposit() Withdraw() Get. Balance() * Customer owns 2 Name Customer. Id 1) Find New Classes 2) Review Names, Attributes and Methods 3) Find Associations between Classes 4) Label the generic assocations 5) Determine the multiplicity of the assocations 6) Review associations Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17

Practice Object Modeling: Find Taxonomies Account Bank * Name Savings Account Withdraw() Bernd Bruegge

Practice Object Modeling: Find Taxonomies Account Bank * Name Savings Account Withdraw() Bernd Bruegge & Allen H. Dutoit Amount Account. Id Customer. Id Account. I d Deposit() Withdraw() Get. Balance() Checking Account Withdraw() * Customer Has Name Customer. Id() Mortgage Account Withdraw() Object-Oriented Software Engineering: Using UML, Patterns, and Java 18

Practice Object Modeling: Simplify, Organize Account Amount Account. Id Customer. Id Account. I d

Practice Object Modeling: Simplify, Organize Account Amount Account. Id Customer. Id Account. I d Deposit() Withdraw() Get. Balance() Savings Account Withdraw() Bernd Bruegge & Allen H. Dutoit Checking Account Withdraw() Show Taxonomies separately Mortgage Account Withdraw() Object-Oriented Software Engineering: Using UML, Patterns, and Java 19

Practice Object Modeling: Simplify, Organize Bank Name Account * Amount Account. Id Customer. Id

Practice Object Modeling: Simplify, Organize Bank Name Account * Amount Account. Id Customer. Id Account. I d Deposit() Withdraw() Get. Balance() * Customer Has Name Customer. Id() Use the 7+-2 heuristics or better 5+-2! Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20

Sequence Diagrams Focus on control flow (Time ordering) ¨ Passenger Ticket. Machine w To

Sequence Diagrams Focus on control flow (Time ordering) ¨ Passenger Ticket. Machine w To refine use case descriptions w to find additional objects (“participating objects”) select. Zone() ¨ insert. Coins() pickup. Change() ¨ Bernd Bruegge & Allen H. Dutoit Used during system design Ticket. Machine w to refine subsystem interfaces zone 2 price Messages -> ¨ Instances are represented by rectangles. select. Zone() Actors by sticky figures. Operations on insert. Coins() participating Object ¨ Lifelines are represented by dashed pickup. Change() lines pick. Up. Ticket() ¨ pick. Up. Ticket() Used during analysis Messages are represented by arrows Activations are represented by narrow rectangles. Object-Oriented Software Engineering: Using UML, Patterns, and Java 21

Sequence Diagrams can also model the Flow of Data Passenger Zone. Button select. Zone()

Sequence Diagrams can also model the Flow of Data Passenger Zone. Button select. Zone() Tarif. Schedule Display lookup. Price(selection) price Dataflow display. Price(price) …continued on next slide. . . ¨ ¨ The source of an arrow indicates the activation which sent the message Horizontal dashed arrows indicate data flow, for example return results from a message Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22

Sequence Diagrams: Iteration & Condition …continued from previous slide. . . Passenger Change. Processor

Sequence Diagrams: Iteration & Condition …continued from previous slide. . . Passenger Change. Processor *insert. Change(coin) Iteration Condition Coin. Identifier Display Coin. Drop lookup. Coin(coin) price display. Price(owed. Amount) [owed. Amount<0] return. Change(-owed. Amount) …continued on next slide. . . ¨ ¨ Iteration is denoted by a * preceding the message name Condition is denoted by boolean expression in [ ] before the message name Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23

Creation and destruction …continued from previous slide. . . Passenger Change. Processor Creation of

Creation and destruction …continued from previous slide. . . Passenger Change. Processor Creation of Ticket create. Ticket(selection) Ticket print() free() ¨ ¨ Destruction of Ticket Creation is denoted by a message arrow pointing to the object Destruction is denoted by an X mark at the end of the destruction activation w In garbage collection environments, destruction can be used to denote the end of the useful life of an object. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24

Sequence Diagram Properties ¨ ¨ UML sequence diagram represent behavior in terms of interactions

Sequence Diagram Properties ¨ ¨ UML sequence diagram represent behavior in terms of interactions Useful to identify or find missing objects Time consuming to build, but worth the investment Complement the class diagrams (which represent structure). Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25

Sequence Diagram(make a phone call) Caller Phone Recipient Picks up Dial tone Dial Ring

Sequence Diagram(make a phone call) Caller Phone Recipient Picks up Dial tone Dial Ring notification Ring Picks up Hello Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26

Sequence Diagram: Object interaction A Self-Call: Self-Call A message that an Object sends to

Sequence Diagram: Object interaction A Self-Call: Self-Call A message that an Object sends to itself. Condition: indicates when a message is sent. The message is sent only if the condition is true. Condition B Synchronous Asynchronous Transmission delayed [condition] remove() *[for each] remove() Iteration Self-Call Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27

Sequence Diagrams – Object Life Spans ¨ ¨ ¨ Creation A w Create message

Sequence Diagrams – Object Life Spans ¨ ¨ ¨ Creation A w Create message w Object life starts at that point Create Activation w Symbolized by rectangular stripes w Place on the lifeline where object is activated. w Rectangle also denotes when object is deactivated. Deletion Activation bar Return w Placing an ‘X’ on lifeline w Object’s life ends at that point Lifeline Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java B X Deletion 28

Sequence Diagram Message • Sequence diagrams demonstrate the behavior of objects in a use

Sequence Diagram Message • Sequence diagrams demonstrate the behavior of objects in a use case by describing the objects and the messages they pass. • The horizontal dimension shows the objects participating in the interaction. • The vertical arrangement of messages indicates their order. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29

Interaction Diagrams: Collaboration diagrams start 6: remove reservation 3 : [not available] reserve title

Interaction Diagrams: Collaboration diagrams start 6: remove reservation 3 : [not available] reserve title User Reservations 5: title available 6 : borrow title 2: title data 1: look up 4 : title returned Catalog • Shows the relationship between objects and the 5 order of messages passed between : hold title them. between them. • The objects are listed as rectangles and arrows indicate the messages being passed • The numbers next to the messages are called sequence numbers. They show the sequence of the messages as they are passed between the objects. • convey the same information as sequence diagrams, but focus on object roles instead of the time sequence. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31

Activity Diagrams ¨ ¨ An activity diagram is a special case of a state

Activity Diagrams ¨ ¨ An activity diagram is a special case of a state chart diagram The states are activities (“functions”) An activity diagram is useful to depict the workflow in a system An activity diagram shows the flow from activity to activity within a system. An activity shows a set of activities, the sequential or branching flow from activity to activity, and objects that act and are acted upon. You use activity diagrams to illustrate the dynamic view of a system. Activity diagrams are especially important in modeling the function of a system. Activity diagrams emphasize the flow of control among objects. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32

Terms & Concepts ¨ Activity Diagram – shows the flow from activity to activity.

Terms & Concepts ¨ Activity Diagram – shows the flow from activity to activity. ¨ Activity – an ongoing non atomic execution within a state machine. Activities ultimately results in some action. ¨ Action – made up of executable atomic computations that results in a change in state of the system or the return of a value (i. e. , calling another operation, sending a signal, creating or destroying an object, or some pure computation. 1/3/2009 Bernd Bruegge & Allen H. Dutoit mahmoodedu@g Object-Oriented Software Engineering: Using UML, Patterns, and Java 33

Activity Diagram Initial state Activity diagrams commonly contain: • Activity states and actions states

Activity Diagram Initial state Activity diagrams commonly contain: • Activity states and actions states • Transitions • Objects Select site Action state Commission architect Develop plan Bid plan concurrent fork Sequential branch [not accepted] [else] Activity state with submachine concurrent join Do trade work() Do site work final state Finish construction Bernd Bruegge & Allen H. Dutoit object flow : Certificate. Of. Occupancy [completed] Object-Oriented Software Engineering: Using UML, Patterns, and Java 34

Action States & Activity States ¨ Action states: executable, atomic computations (states of the

Action States & Activity States ¨ Action states: executable, atomic computations (states of the system, each representing the execution of an action) – cannot be decomposed. ¨ Activity states: not atomic; can be further decomposed; can be represented by other activity diagrams – a composite whose flow of control is made up of other activity states and action states. 1/3/2009 Bernd Bruegge & Allen H. Dutoit mahmoodedu@gmail. co Object-Oriented Software Engineering: Using UML, Patterns, and Java 35

Transitions & Branching start state guard expression Release work order branch Select Site action

Transitions & Branching start state guard expression Release work order branch Select Site action state [materials not ready] Reschedule triggerless transition Commission architect [materials ready] Assign tasks stop state guard expression 1/3/2009 Bernd Bruegge & Allen H. Dutoit mahmoodedu@gmail. com, Dept of cse, uce(a), ou, hyd, Object-Oriented Software Engineering: Using UML, Patterns, and Java 36

Forking and Joining ¨ Concurrent flow. ¨ Use synchronization bar to specify the forking

Forking and Joining ¨ Concurrent flow. ¨ Use synchronization bar to specify the forking and joining of these parallel flows of control. ¨ A synchronization bar is rendered as a thick horizontal or vertical line. 1/3/2009 Bernd Bruegge & Allen H. Dutoit fork Do trade Do site work mahmoodedu@gmail. c Object-Oriented Software Engineering: Using UML, Patterns, and Java work() join 37

Swimlanes ¨ Useful in modeling workflows of business processes – partition the activity states

Swimlanes ¨ Useful in modeling workflows of business processes – partition the activity states on an activity diagram into groups, each group representing the business organization responsible for those activities. ¨ A swimlane is a kind of package. ¨ Each swimlaine has a name unique within its diagram (a swimlane really has no deep semantic – just represent some real-world entity). ¨ Every activity belongs to exactly one swimlane, but transitions may cross lanes. 1/3/2009 Bernd Bruegge & Allen H. Dutoit mahmoodedu@gmail. com Object-Oriented Software Engineering: Using UML, Patterns, and Java 38

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39

Object Flow ¨ Objects may be involved in the flow of control associated with

Object Flow ¨ Objects may be involved in the flow of control associated with an activity diagram. ¨ Specify the things that are involved in an activity diagram by placing these objects in the diagram, connected using a dependency to the activity or transition that creates, destroys, or modifies them. ¨ Object flow – the use of dependency relationships and objects (represents the participation of an object in a flow of control). Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40

Activity Diagrams allow to model Decisions (General strategy in Mind) Decision Bernd Bruegge &

Activity Diagrams allow to model Decisions (General strategy in Mind) Decision Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41

Activity Diagrams can model Concurrency (General strategy in Mind IMPROVED) ¨ ¨ Synchronization of

Activity Diagrams can model Concurrency (General strategy in Mind IMPROVED) ¨ ¨ Synchronization of multiple activities Splitting the flow of control into multiple threads Splitting Bernd Bruegge & Allen H. Dutoit Synchronization Object-Oriented Software Engineering: Using UML, Patterns, and Java 42

Statechart Diagrams ¨ ¨ ¨ A statechart diagram shows a state machine, consisting of

Statechart Diagrams ¨ ¨ ¨ A statechart diagram shows a state machine, consisting of states, transitions, events, and activities. You use statechart diagrams to illustrate the dynamic view of a system. They are especially important in modeling the behavior of an interface, class, or collaboration. Statechart diagrams emphasize the event-ordered behavior of an object, which is especially useful in modeling reactive systems. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43

UML Summary ¨ UML provides a wide variety of notations for representing many aspects

UML Summary ¨ UML provides a wide variety of notations for representing many aspects of software development w Powerful, but complex ¨ UML is a programming language w Can be misused to generate unreadable models w Can be misunderstood when using too many exotic features ¨ We concentrated on a few notations: w Functional model: Use case diagram w Object model: class diagram w Dynamic model: sequence diagrams, statechart and activity diagrams Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 44

Additional References ¨ Martin Fowler w UML Distilled: A Brief Guide to the Standard

Additional References ¨ Martin Fowler w UML Distilled: A Brief Guide to the Standard Object Modeling Language, 3 rd ed. , Addison-Wesley, 2003 ¨ Grady Booch, James Rumbaugh, Ivar Jacobson w The Unified Modeling Language User Guide, Addison Wesley, 2 nd edition, 2005 ¨ Commercial UML tools w Rational Rose XDE for Java t http: //www-306. ibm. com/software/awdtools/developer/java/ w Together (Eclipse, MS Visual Studio, JBuilder) t ¨ http: //www. borland. com/us/products/together/index. html Open Source UML tools w http: //java-source. net/open-source/uml-modeling w Argo. UML, UMLet, Violet, … Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45