Using UML Patterns and Java ObjectOriented Software Engineering
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 3, Activity Diagrams
What is UML? • UML (Unified Modeling Language) • Nonproprietary standard for modeling software systems, OMG • Convergence of notations used in object-oriented methods • OMT (James Rumbaugh and collegues) • Booch (Grady Booch) • OOSE (Ivar Jacobson) • Current Version: UML 2. 2 • Information at the OMG portal http: //www. uml. org/ • Commercial tools: Rational (IBM), Together (Borland), Visual Architect (business processes, BCD) • Open Source tools: Argo. UML, Star. UML, Umbrello, Lucid. Chart • Commercial and Opensource: Poseidon. UML (Gentleware) Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2
What is UML? Unified Modeling Language • Convergence of different notations used in object-oriented methods, mainly • OMT (James Rumbaugh and collegues), OOSE (Ivar Jacobson), Booch (Grady Booch) • They also developed the Rational Unified Process, which became the Unified Process in 1999 Developed the Booch method 25 year at GE Research, (“clouds”), ACM where he developed OMT, Fellow 1995, and joined (IBM) Rational in IBM Fellow 2003 1994, CASE tool OMTool http: //www. booch. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3 com/ At Ericsson until 1994, developed use cases and the CASE tool Objectory, at IBM Rational since 1995, http: //www. ivarjacobson. com
UML: First Pass • You can model 80% of most problems by using about 20% UML • We teach you those 20% • 80 -20 rule: Pareto principle: For many events, roughly 80% of the effects come from 20% of the causes. Vilfredo Pareto, 1848 -1923 Introduced the concept of Pareto Efficiency, Founder of the field of microeconomics. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4
UML Core Conventions • All UML Diagrams denote graphs of nodes and edges • Nodes are entities and drawn as rectangles or ovals • Rectangles denote classes or instances • Ovals denote functions • Names of Classes are not underlined • Simple. Watch • Firefighter • Names of Instances are underlined • my. Watch: Simple. Watch • Joe: Firefighter • An edge between two nodes denotes a relationship between the corresponding entities Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
Outline of this Class • Activity diagrams • Describe the dynamic behavior of a system, in particular the workflow. • Class diagrams • Describe the static structure of the system: Objects, attributes, associations • Use case diagrams • Describe the functional behavior of the system as seen by the user • Sequence diagrams • Describe the dynamic behavior between objects of the system • Statechart diagrams • Describe the dynamic behavior of an individual object Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
UML Activity Diagrams: Activities and Actions An activity is a non-atomic task or procedure decomposable into actions. An action is a task or procedure that cannot be broken into parts. Actions and activities can be anything that humans, machines, organizations, or other entitites do. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
Activity Graph Elements initial node action node activity symbol activity edge activity final node Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8
UML 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. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9
Branching Nodes merge node decision node Bernd Bruegge & Allen H. Dutoit guards Object-Oriented Software Engineering: Using UML, Patterns, and Java 10
Execution Model • Execution is modeled by tokens that are produced by action nodes, travel over action edges, and are consumed by action nodes. • When there is a token on every incoming edge of an action node, it consumes them and begins execution. • When an action node completes execution, it produces tokens on each of its outgoing edges. • An initial node produces a token on each outgoing edge when an activity begins. • An activity final node consumes a token available on any incoming edge and terminates the activity. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
Branching Execution Decision and merge node behavior: • If a token is made available on the incoming edge of a decision node, the token is made available on the outgoing edge whose guard is true. • If a token is available on any incoming edge of a merge node, it is made available on its outgoing edge. • Guards must be mutually exclusive. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
Deadlock Run. Drier cannot execute: when the activity begins, there is a token on the edge from the initial node but not on the other incoming edge. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13
Forking and Joining Nodes fork node join node Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14
Forking and Joining Execution • A token available on the incoming edge of a fork node is reproduced and made available on all its outgoing edges. • When tokens are available on every incoming edge of a join node, a token is made available on its outgoing edge. • Concurrency can be modeled without these nodes. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15
Concurrent Problem Solution (An example) Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16
Object Nodes Data and objects are shown as object nodes. object node state object node Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17
Control and Data Flows • Control tokens do not contain data, data tokens do. • A control flow is an activity edge that is a conduit for control tokens. • A data flow is an activity edge that is a conduit for data tokens. • Rules for token flow through nodes apply to both control and data tokens, except that data is extracted from consumed tokens and added to produced tokens. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18
Control and Data Flow Example control flow data flows control flow Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19
Activity Parameters • Activity parameters are object nodes placed on activity symbol boundaries to indicate data or object inputs or outputs. • Activity parameters contain the data or object name. • Activity parameter types are specified in the activity symbol beneath the activity name. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20
Activity Parameter Example: Maximum Finding Algorithm activity parameter types input activity parameter output activity parameter Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21
Activity Diagram Heuristics • Flow control and objects down the page and left to right. • Name activities and actions with verb phrases. • Name object nodes with noun phrases. • Don’t use both control and data flows when a data flow alone can do the job. • Make sure that all nodes entering an action node can provide tokens concurrently (to prevent deadlocks). • Use the [else] guard at every branch. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22
When to Use Activity Diagrams When making a dynamic model of any process. • Design processes (what designers do) • Designed processes (what designers create) • During analysis • During resolution Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23
Activity Diagrams allow to model Decisions Decision Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24
Activity Diagrams can model Concurrency • 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 25
Activity Diagrams: Grouping of Activities • Activities may be grouped into swimlanes to denote the object or subsystem that implements the activities. Open Incident Allocate Resources Dispatcher Coordinate Resources Archive Incident Field. Officer Document Incident Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26
Activity Diagram vs. Statechart Diagram for Incident Focus on the set of attributes of a single abstraction (object, system) Event causes state transition Active Inactive Incident. Handled Closed Incident. Documented Archived Incident. Archived Activity Diagram for Incident (Focus on dataflow in a system) Completion of activity causes state transition Bernd Bruegge & Allen H. Dutoit Triggerless transition Object-Oriented Software Engineering: Using UML, Patterns, and Java 27
Example of an Activity Diagram with a Frame Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28
The Activity Diagram without Frame Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29
Activity Diagram Example Object node Bernd Bruegge & Allen H. Dutoit Action Object-Oriented Software Engineering: Using UML, Patterns, and Java 30
Activity Diagram: Activity Nodes & Edges • An activity diagram consists of nodes and edges • There are three types of activity nodes üControl nodes üExecutable nodes • Most prominent: Action üObject nodes • E. g. a document • An edge is a directed connection between nodes • There are two types of edges • Control flow edges • Object flow edges Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31
Activity Diagram Example Control flow Object flow Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 32
Summary: Activity Diagram Example Fork node Join node Initial node Control flow Merge node Final node Object node Bernd Bruegge & Allen H. Dutoit Action Object flow Object-Oriented Software Engineering: Using UML, Patterns, and Java 33
Example 1: What the diagram represents? a. A document b. A printer c. A wordprocessor d. A user of a word -processor e. A page being printed f. The diagram is invalid Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34
Example 2: What is the max number of concurrent threads that is possible? a. b. c. d. e. 1 2 3 4 5 Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35
Example 3: In this diagram. . . a. b. c. d. e. f. Fill Order is executed before Receive Payment Overnight Delivery is executed in parallel with Regulary Delivery Close Order is executed after Receive Payment Fill Order is executed in parallel with Send Invoice is possibly executed Regular Delivery is always executed Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36 36
Example 4: Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37
Example 5: Cash Withdrawal Process from a Bank Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38
Example 6: Passenger to Airplane There should be only one final node, not two!!! Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39
Alıştırma (10 dakika) Müşteri restorana girer. Eğer oturacak yer varsa oturur, yoksa çıkar. Oturduktan sonra menüye bakar. İki seçeneği vardır: Çin yemeği, Japon yemeği. İkisini de yemek istemiyorsa çıkar gider. İstediği yemeği seçer, garsona söyler. Garson mutfağa siparişi geçer. Yemekler hazır olduğunda garson yemeği müşteriye götürür. Müşteri yemeği yedikten sonra hesap ister. Eğer memnun kaldıysa hesabı ödeyip bahşiş bırakır. Eğer memnun kalmadıysa hesabı öder, bahşiş bırakmadan restorandan çıkar. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40
Summary • A process is a collection of related tasks that transforms a set of inputs to a set of outputs. • UML activity diagrams model processes by depicting actions and the flow of control and data between them. • Activity symbols contain activity graphs consisting of • • action nodes action edges data nodes special nodes for starting and stopping activities, branching, forking, and joining • Activity diagrams can represent any process and are useful throughout software design. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41
Another view on UML Diagrams Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42
- Slides: 42