activitydiagram.ppt
TRANSCRIPT
-
7/30/2019 ActivityDiagram.ppt
1/64
CS 537 Group 3 Report:Activity Diagrams and
Observer Design Pattern
Anna Deghdzunyan
Xuan Yang
Keenan Knaur
John Hurley
-
7/30/2019 ActivityDiagram.ppt
2/64
Part I: Activity Diagrams
-
7/30/2019 ActivityDiagram.ppt
3/64
Introduction(I)
Activity diagrams describe procedural logic,business process, and workflow.
Activity diagrams focus on the action sequenceof execution and the conditions that trigger or
guard those actions.
Activity diagrams focus on the activitys internalactions, not on the external interfaces
-
7/30/2019 ActivityDiagram.ppt
4/64
Introduction(II)
Activity diagrams have similarities to flowcharts
But flowcharts notation does not support parallelbehavior.
Business managers may prefer activity diagramsover flowcharts, because they are moreunderstandable for non-technical people.
An activity diagram is a special case of statechart diagram in which states are actions.
-
7/30/2019 ActivityDiagram.ppt
5/64
Introduction(III)
An activity diagram shows flow control within asystem.
HandleIncident
ArchiveIncident
DocumentIncident
-
7/30/2019 ActivityDiagram.ppt
6/64
Activity Diagram Elements
Initial node
Activity final node
Action
Flow/edge
Fork
Join Decision
Merge
Synch
-
7/30/2019 ActivityDiagram.ppt
7/64
Basic Elements
Action(I)
Action in Activity Diagram Elements officialUML name is action state.
Distinction between action and activity
Action state refers to it as action Use term activityonly refer to the whole task
being modeled by the activity diagram
-
7/30/2019 ActivityDiagram.ppt
8/64
Basic Elements
Action(II)
The rounded rectangle represents an action thatoccurs.
E.g., Customer calls ticket office :
A sample action that is part of an activity diagram
Customer Calls TicketOffice
-
7/30/2019 ActivityDiagram.ppt
9/64
Basic Elements--Initial state
The filled circle is the staring point of thediagrams.
An initial node isnt required.
The initial state shows the starting point for the action sequencewithin an activity diagram.
First Action To DO
-
7/30/2019 ActivityDiagram.ppt
10/64
Basic Elements--Initial state(II)
Initial state can indicate onlyONE action.
Incorrect rendering of an initial state within anactivity diagram. The initial state can indicate onlyONE action
Action 1
Action 2
-
7/30/2019 ActivityDiagram.ppt
11/64
Basic Elements
Flow/edge
The arrow on the diagram. There is a subtledifference between flows and edges.
-
7/30/2019 ActivityDiagram.ppt
12/64
Basic Elements
Final node
The filled circle with a border is the ending point.
An activity diagram can have zero or more activityfinal nodes
First Action To DO
-
7/30/2019 ActivityDiagram.ppt
13/64
Decision
A diamond with one flow entering and severalleaving.
[Drink contains
alcohol]
[else] Get Drink ForCustomer
Make Sure Customer IsAt least 21 Years Old
CustomerOrders Drink
-
7/30/2019 ActivityDiagram.ppt
14/64
Merge
A diamond with several flows entering and oneleaving.
[customers age < 21]
[Drink containsalcohol]
[customers age >= 21]
[else]
Customer
Orders Drink
Make SureCustomer Is At
least 21 Years Old
Get Drink ForCustomer
Tell Customer ToOrder A Non
Alcoholic Drink
-
7/30/2019 ActivityDiagram.ppt
15/64
Synch
A thick, solid line, allowing two or more actionsequences to proceed in parallel
Action 1
-
7/30/2019 ActivityDiagram.ppt
16/64
Fork Synch with one flow going into it and several
leaving it.
Denotes the beginning of parallel actions.
Receive Order
Verify CustomerHas Available
Credit
Verify OrderProducts Are InStock
-
7/30/2019 ActivityDiagram.ppt
17/64
Join Synch with several flows entering and one leaving.
All incoming flows must reach it before processingmay continue. This denotes the end of parallel
processing.Verify Order
Products Are InStock
Verify CustomerHas Available
Credit
Accept Order
-
7/30/2019 ActivityDiagram.ppt
18/64
Signals
An Activity diagram can have a clearly defined startpoint, which corresponds to an invocation of a
program or routine. Activity diagram can also show response to signals.
A time signal occurs because of the passage of time(for example, each month end might trigger a signal.)
A real time signal indicates that the activity receivesan event from an outside process.
The activity listens for those signals, and thediagram defines how the activity reacts.
-
7/30/2019 ActivityDiagram.ppt
19/64
Signals Activity diagrams can show signals sent or
received
For example, we can send a message and thenwait for a reply before we can continue.
Basically, the signals are flow triggers.
Send signal Time signal Accept signal
-
7/30/2019 ActivityDiagram.ppt
20/64
Flow
Connection between 2 actions Simple flow
- arrow- from a node to another
Flow with Exception
-
7/30/2019 ActivityDiagram.ppt
21/64
Flows (cont.)
Flow with objects
Flow with pins- similar to flows with objects
- data needed and data produced
-
7/30/2019 ActivityDiagram.ppt
22/64
Flows (cont.)
Decision flows
-labeled
Connectors- does the same job as a simplearrow
-
7/30/2019 ActivityDiagram.ppt
23/64
Tokens flow through the diagrams:
The initial node creates a token, executes, passes
the token to the next Fork produces a token on each of its outward
flows.
On a join, as each inbound token arrives, nothinghappens until all the tokens appear at the join;then a token is produced on the outward flow.
Tokens
-
7/30/2019 ActivityDiagram.ppt
24/64
Join Specification Boolean expression using the names of the incoming
edges to specify the conditions under which the join willemit a token.
Evaluatedwhenever a new token is offered on anyincoming edge.
Default - "and
-
7/30/2019 ActivityDiagram.ppt
25/64
Expansion Region
Structured activity regionthat executes multipletimes corresponding toelements of an input
collection.
Example:
The hotels may be bookedindependently andconcurrently with each otherand with booking the flight.
-
7/30/2019 ActivityDiagram.ppt
26/64
Advanced Notation
Conditional threads
Nested activity diagrams
Partitions
-
7/30/2019 ActivityDiagram.ppt
27/64
Conditional threads
One of a set ofconcurrent threads isconditional.
Example:
Frequent-flyermember?
Award the passengerfrequent flyer miles.
-
7/30/2019 ActivityDiagram.ppt
28/64
Nested Activity Diagram
diagram refers to anexternal one that usesmore abstraction
-
7/30/2019 ActivityDiagram.ppt
29/64
Partitions
The contents of an activity
diagram may be organizedintopartitions
Does not have a formalsemantic interpretation
May represent
organizational unit
-
7/30/2019 ActivityDiagram.ppt
30/64
Dimensional Partition
-
7/30/2019 ActivityDiagram.ppt
31/64
Dimensional Partition
Dimensional Partition
Dimensional Partition
-
7/30/2019 ActivityDiagram.ppt
32/64
Dimensional Partition
Multidimensional Hierarchical Diagram
-
7/30/2019 ActivityDiagram.ppt
33/64
Activity vs. Sequence Diagrams
Activity diagrams give focus to theworkflow
Sequence diagrams give focus to the handling ofbusiness entities.
Activity diagram with partitions focuses on how youdivide responsibilities onto classes
The sequence diagram helps you understand howobjects interact and in what sequence.
-
7/30/2019 ActivityDiagram.ppt
34/64
When to Use Activity Diagrams Describe a behavior which contains parallel
activities
Or
Show how behaviors in several use-cases interact.
-
7/30/2019 ActivityDiagram.ppt
35/64
Specification standards
No need for documenting the Activity diagrams
beyond diagram itself.
However, most UML tools provide in-built
documentation capturing and printingcapabilities for the Activity diagram and itselements.
UML A ti it di dit
-
7/30/2019 ActivityDiagram.ppt
36/64
UML Activity diagram editor
-
7/30/2019 ActivityDiagram.ppt
37/64
Questions on Activity Diagrams
-
7/30/2019 ActivityDiagram.ppt
38/64
Part II: Observer Design Pattern
Also Known As:
Dependents,
Publish-Subscribe,and confusingly, Model-View
-
7/30/2019 ActivityDiagram.ppt
39/64
Introduction to Observer AGang of Four design pattern, one of the patterns
discussed inDesign Patterns: Elements of ReusableObject-Oriented Softwareby Erich Gamma, RichardHelm, Ralph Johnson, and John Vlissides.
Observer defines a one-to-many or many-to-manydependency between objects.
When the state of one object changes, then all the
other objects that are dependent on that object areupdated automatically. Used for event handling where consistency between
objects is necessary, e.g. Swing Framework for GUIdevelopment.
-
7/30/2019 ActivityDiagram.ppt
40/64
General Example Suppose you have some data
that can be displayed by atable, a bar graph or a pie
chart.
Changes to the underlyingdata should be reflected in allthree of the displays
This is where the Observer
Design Pattern comes inhandy.
-
7/30/2019 ActivityDiagram.ppt
41/64
Motivation for Using Maintaining consistency between related objects
is necessary when a system contains a collection
of cooperating classes This consistency shouldnt be accomplished
through tightly coupling the classes since thisreduces the reusability of those tightly coupled
classes. Needs to be scalable. There should also be no
limit on the number of objects that depend onone or more other objects.
-
7/30/2019 ActivityDiagram.ppt
42/64
You are coding an app in which a weather station updates three objects, one that displayscurrent conditions, one that calcs statistics over time (up to date), and one that makes aforecast.
Here is the obvious approach:
public class WeatherData {[declarations and getters/setters omitted]
public void measurements changed(){float temp = getTemperature();float humidity = getHumidity();float pressure = getPressure();
currentConditionsDisplay.update(temp, humidity, pressure);
statisticsDisplay.update(temp, humidity, pressure);forecastDisplay.update(temp, humidity, pressure);
}}
Freeman, Freeman, Sierra, and Bates, Head First Design Patterns,OReilly 2004
Example of the Problem:
-
7/30/2019 ActivityDiagram.ppt
43/64
public void measurementsChanged(){float temp = getTemperature();
float humidity = getHumidity();
float pressure = getPressure();
currentConditionsDisplay.update(temp, humidity, pressure);
statisticsDisplay.update(temp, humidity, pressure);
forecastDisplay.update(temp, humidity, pressure);
}
Problems:
Area that is likely to change is mixed with area that is not likely to change update() calls are coded to concrete objects, not types
Need to change code if the subscribers change
Observer addresses these problems
Problems With The Obvious Approach
-
7/30/2019 ActivityDiagram.ppt
44/64
Three Major Aspects of Observer1. The Subject, which is the object being
observed
2. The Observer, which observes a Subject3. Relationship between 1 and 2: attach/detach
(or subscribe / unsubscribe) and update
-
7/30/2019 ActivityDiagram.ppt
45/64
Generalized Structure
-
7/30/2019 ActivityDiagram.ppt
46/64
Generalized Structure (cont.) Subject
Interface for ConcreteSubjects Requires implementations to provide at least the following
methods: subscribe / attach unsubscribe / detach notify all observers of state changes
ConcreteSubject
Implements the Subject interface Maintains direct or indirect references to one or moreConcreteObservers
Keeps track of its own state When its state changes it sends a notification to all of its
Observers by calling their update() methods
-
7/30/2019 ActivityDiagram.ppt
47/64
Generalized Structure (cont.) Observer
Interface for ConcreteObserver objects
Requires an update method
ConcreteObserver
This is the actual object that is observing the stateof the ConcreteSubject.
The state that it maintains should always beconsistent with the state of its Subject.
Implements update() method.
-
7/30/2019 ActivityDiagram.ppt
48/64
-
7/30/2019 ActivityDiagram.ppt
49/64
Two Ways to Implement Updates The Push Model
Subject sends all of the necessary information about any of its changes toall the Observers.
Pushes information to the Observer as parameter with the update()method.
Requires assumptions about what the Observers need to know. May need to allow for subscription to relevant changes only, but this
adds complexity The Pull Model
The Subject sends an indication to the Observer that a change has
occurred. Observers use public methods of Subject to query information they want It is up to the Observer topullall of the necessary information from the
Subject in order to effect any relevant changes. Subject requires fewer assumptions about what the observers want to
know
-
7/30/2019 ActivityDiagram.ppt
50/64
General Implementation Subjects can track Observers through ArrayLists
or other data structures.
Observers can track multiple Subjects and getdifferent data from each.
Pull model uses an update method that takes a
reference to Subject as a parameter. The Subject should trigger updates when itsstate changes.
-
7/30/2019 ActivityDiagram.ppt
51/64
General ImplementationMethods that change state may call a stateChanged() method:
public void notifyObservers(){for(Observer o: observers)
o.update();
}
public void stateChanged(){// do other things
notifyObservers();
// do whatever else still needs doing}
public void setMeasurements(arguments.) {// set instance variables first
stateChanged();}
-
7/30/2019 ActivityDiagram.ppt
52/64
Simple Example: Swing Button With Listeners
Swing JButtons are Subjects; Listeners are Observers
JButton extends AbstractButton, an abstract class thatrequires methods to add and remove listeners, as wellas several types of notify() methods
ActionListener requires that implementers haveactionPerformed() method (update())
Can add as many listeners as you like to JButton, aslong as they implement ActionListener
-
7/30/2019 ActivityDiagram.ppt
53/64
Familiar Example: Swing Button With Listenerspublic class SwingObserverExample{
Jframe frame;[stuff omitted]
public void go() {frame = new JFrame();JButton button = new JButton("Should I do it?");
button.addActionListener(new AngelListener());button.addActionListener(new DevilListener());frame.getContentPane().add(BorderLayout.CENTER, button);[frame property code omitted]
}
// using inner classes in this very simple exampleclass AngelListener implements ActionListener {
public void actionPerformed(ActionEvent event) {System.out.println("Don't do it");
}
}
class DevilListener implements ActionListener {public void actionPerformed(ActionEvent event) {
System.out.println("Come on, do it!");}
}}
When we click the button, both listeners are notified and take action.Freeman Freeman Sierra and Bates Head First Desi n Patterns OReill 200 .
-
7/30/2019 ActivityDiagram.ppt
54/64
Implementation in Java Java has built-in support for Observer
java.util.Observable class can be extended bya Subject
java.util.Observer interface can beimplemented by a class that wants to observe aSubject
-
7/30/2019 ActivityDiagram.ppt
55/64
UML Diagram for
Observable/Observer Classes
-
7/30/2019 ActivityDiagram.ppt
56/64
Methods in java.util.Observable Observable()
Creates an Observable object (Subject) with no Observers initially setChanged()
Indicates that this Subject has changed in some way.
hasChanged() Returns True if the setChanged() method has been called more recently
than the clearChanged() method. Returns False if otherwise.
clearChanged() Indicates that this object is done notifying all of its observers of its most
recent changes. It is called automatically by notifyObservers() method countObservers()
Returns the number of objects that are Observing this Subject.
-
7/30/2019 ActivityDiagram.ppt
57/64
Methods in java.util.Observable (cont.)
addObserver(Observer o)
Adds the passed Observer object to the list of
Observers kept by the Subject deleteObserver(Observer o) / deleteObservers()
Removes the passed Observer object or all of theObserver objects respectively from the list of
Observers kept by the Subject
-
7/30/2019 ActivityDiagram.ppt
58/64
Methods in java.util.Observable (cont.)
notifyObservers(Object arg) / notifyObservers()
If this Subject has changed, this method notifies
all of its Observers and then calls theclearChanged() method. When given an arg as aparameter in the function call, the Observer knowswhich attribute of the Subject has changed
otherwise the Observer can be notified withoutspecifying an arg.
-
7/30/2019 ActivityDiagram.ppt
59/64
Methods in java.util.Observer update(Observable o, Object arg)
Called when the Subject has changed. o is the
Subject in question, and arg is an argument thatcan be passed to tell the Observer which attributeof the Subject has changed.
-
7/30/2019 ActivityDiagram.ppt
60/64
Limitations of Built-In Implementation
Observable is a class, not an interface
Cant add its behavior to a concrete class thatsubclasses something else.
Since there is no Observable interface, you cantcreate an impl that works with Observer butdoesnt subclass Observable.
Cant compose another class that has an
Observable since setChanged() is protected
-
7/30/2019 ActivityDiagram.ppt
61/64
Questions on Observer Pattern
-
7/30/2019 ActivityDiagram.ppt
62/64
Benefits of the Observer Pattern Minimal coupling between the Subject and Observer
Objects
Many Observers can be added to a Subject withouthaving to modify the Subject. Reuse of Subjects without needing to also reuse any
of their Observers. The opposite also holds true. The only thing a Subject needs to keep track of is its
list of Observers. The Subject does not need to know the concrete
classes of its Observers, only that each oneimplements the Observer interface
-
7/30/2019 ActivityDiagram.ppt
63/64
Trouble Spots
Cascading notifications if Observers update their ownclients or if they can also make changes to the Subject Repeated notifications when sequences of changes
occur. Dangling references to Subjects or Observerswhen
either type are manually deleted in non-garbagecollected environments. Need to notify Observerswhen Subjects are deleted and vice-versa.
Subject state must be self-consistent before callingnotify(), especially with pull model.
Careful not to push irrelevant information onobservers with push model.
If update() fails, the Observer wont know that itmissed potentially important information
References
-
7/30/2019 ActivityDiagram.ppt
64/64
ReferencesBooks:
Freeman, Freeman, Sierra, and Bates, Head First Design Patterns,OReilly 2004, p. 73
Gamma, Helm, Johnson, and Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley1995.
Websites:
Activity Diagrams:
http://www.agilemodeling.com/artifacts/activityDiagram.htm
http://computersciencesource.wordpress.com/2010/03/15/software-engineering-activity-diagrams/
http://www.cse.unt.edu/~rgoodrum/Teaching/2009/fall/4910/website%20files/handouts/umlbasicsp2_actdg.pdf
http://www.devx.com/ibm/Article/21615
http://edutechwiki.unige.ch/en/UML_activity_diagram http://www.sa-depot.com/?p=158
http://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagrams
http://www.uml-diagrams.org/activity-diagrams.html
Observer:
http://www.blackwasp.co.uk/Observer.aspx
http://www.cs.clemson.edu/~malloy/courses/patterns/observer.html
http://www.codeproject.com/KB/architecture/Observer_Design_Pattern.aspx
http://java.dzone.com/articles/observer-pattern?utm_source=am6_feedtweet&utm_medium=twitter&utm_campaign=toya256ForRSS
http://www.patterndepot.com/put/8/observer.pdf
http://sourcemaking.com/design_patterns/observer
http://userpages.umbc.edu/~tarr/dp/lectures/Observer.pdf
h // ikib k / iki/J P i /D i P Ob
http://www.agilemodeling.com/artifacts/activityDiagram.htmhttp://computersciencesource.wordpress.com/2010/03/15/software-engineering-activity-diagrams/http://www.cse.unt.edu/~rgoodrum/Teaching/2009/fall/4910/website%20files/handouts/umlbasicsp2_actdg.pdfhttp://www.devx.com/ibm/Article/21615http://edutechwiki.unige.ch/en/UML_activity_diagramhttp://www.sa-depot.com/?p=158http://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://www.uml-diagrams.org/activity-diagrams.htmlhttp://www.blackwasp.co.uk/Observer.aspxhttp://www.cs.clemson.edu/~malloy/courses/patterns/observer.htmlhttp://www.codeproject.com/KB/architecture/Observer_Design_Pattern.aspxhttp://java.dzone.com/articles/observer-pattern?utm_source=am6_feedtweet&utm_medium=twitter&utm_campaign=toya256ForRSShttp://java.dzone.com/articles/observer-pattern?utm_source=am6_feedtweet&utm_medium=twitter&utm_campaign=toya256ForRSShttp://www.patterndepot.com/put/8/observer.pdfhttp://sourcemaking.com/design_patterns/observerhttp://userpages.umbc.edu/~tarr/dp/lectures/Observer.pdfhttp://en.wikibooks.org/wiki/Java_Programming/Design_Patternshttp://en.wikibooks.org/wiki/Java_Programming/Design_Patternshttp://userpages.umbc.edu/~tarr/dp/lectures/Observer.pdfhttp://userpages.umbc.edu/~tarr/dp/lectures/Observer.pdfhttp://sourcemaking.com/design_patterns/observerhttp://www.patterndepot.com/put/8/observer.pdfhttp://www.patterndepot.com/put/8/observer.pdfhttp://java.dzone.com/articles/observer-pattern?utm_source=am6_feedtweet&utm_medium=twitter&utm_campaign=toya256ForRSShttp://java.dzone.com/articles/observer-pattern?utm_source=am6_feedtweet&utm_medium=twitter&utm_campaign=toya256ForRSShttp://java.dzone.com/articles/observer-pattern?utm_source=am6_feedtweet&utm_medium=twitter&utm_campaign=toya256ForRSShttp://www.codeproject.com/KB/architecture/Observer_Design_Pattern.aspxhttp://www.cs.clemson.edu/~malloy/courses/patterns/observer.htmlhttp://www.blackwasp.co.uk/Observer.aspxhttp://www.uml-diagrams.org/activity-diagrams.htmlhttp://www.uml-diagrams.org/activity-diagrams.htmlhttp://www.uml-diagrams.org/activity-diagrams.htmlhttp://www.uml-diagrams.org/activity-diagrams.htmlhttp://www.uml-diagrams.org/activity-diagrams.htmlhttp://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://sourcemaking.com/uml/modeling-business-systems/external-view/activity-diagramshttp://www.sa-depot.com/?p=158http://www.sa-depot.com/?p=158http://www.sa-depot.com/?p=158http://edutechwiki.unige.ch/en/UML_activity_diagramhttp://www.devx.com/ibm/Article/21615http://www.cse.unt.edu/~rgoodrum/Teaching/2009/fall/4910/website%20files/handouts/umlbasicsp2_actdg.pdfhttp://computersciencesource.wordpress.com/2010/03/15/software-engineering-activity-diagrams/http://computersciencesource.wordpress.com/2010/03/15/software-engineering-activity-diagrams/http://computersciencesource.wordpress.com/2010/03/15/software-engineering-activity-diagrams/http://computersciencesource.wordpress.com/2010/03/15/software-engineering-activity-diagrams/http://computersciencesource.wordpress.com/2010/03/15/software-engineering-activity-diagrams/http://computersciencesource.wordpress.com/2010/03/15/software-engineering-activity-diagrams/http://computersciencesource.wordpress.com/2010/03/15/software-engineering-activity-diagrams/http://www.agilemodeling.com/artifacts/activityDiagram.htm