Software Engineering I (02161) activity diagram only shows one perspective of the dynamic aspect of...
Transcript of Software Engineering I (02161) activity diagram only shows one perspective of the dynamic aspect of...
Software Engineering I (02161)Week 5
Assoc. Prof. Hubert Baumeister
Informatics and Mathematical ModellingTechnical University of Denmark
Spring 2011
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 5 / 65
Recap
Recap: Class Diagrams
Class diagram: Visualize OO programs (i.e. based on OOprogramming languages)→ However, have more abstract language
Classes: combines data and methods related to a commonaspect (e.g. Person, Address, Company, . . . )Generalization between classes (corresponds to inheritance)Association between classes
UnidirectonalAssociations vs. attributes
Multiplicities and how to implement them: 0..1, 1, *Bi-directionalQualifed assocations: Corresponds to the use of maps ordictionariesAggregation and Composition
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 7 / 65
Activity Diagrams
Activity Diagram: Business Processes
Describe the context of the systemHelps finding the requirements of a system
modelling business processes leads to suggestions for possiblesystems and ways how to interact with themSoftware systems need to fit in into existing business processes
Ian Sommerville, Software Engineering – 9, 2010
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 9 / 65
Activity Diagrams
Activity Diagram Example Workflow
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 10 / 65
Activity Diagrams
Activity Diagram Example Operation
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 11 / 65
Activity Diagrams
UML Activity Diagrams
Focus is on control flow and data flowGood for showing parallel/concurrent control flowPurpose
Model business processesModel workflowsModel single operations
Literature: UML Distilled by Martin Fowler
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 12 / 65
Activity Diagrams
Activity Diagram Concepts
ActionsAre atomicE.g Sending a message, doing some computation, raising anexception, . . .
UML has approx. 45 Action typesConcurrency
Fork: Creates concurrent flowsCan be true concurrencyCan be interleaving
Join: Synchronisation of concurrent activitiesWait for all concurrent activities to finish (based on token semantics)
DecisionsNotation: Diamond with conditions on outgoing transitionselse denotes the transition to take if no other condition is satisfied
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 13 / 65
Activity Diagrams
Activity Diagrams Execution
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 14 / 65
Activity Diagrams
Swimlanes / Partitions
Swimlanes show who is performing an activity
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 15 / 65
Activity Diagrams
Objectflow example
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 16 / 65
Activity Diagrams
Data flow and Control flow
Data flow and control flow are shown:
Order MakePayment
ReceiveInvoice
Control flow can be omitted if implied by the data flow:
Order MakePayment
ReceiveInvoice
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 17 / 65
Activity Diagrams
Use of Activity Diagrams
Emphasise on concurrent/parallel executionRequirements phase
To model business processes / workflows to be automatedDesign phase
Show the semantics of one operationClose to a graphic programming language
An activity diagram only shows one perspective of the dynamicaspect of the system
Use several activity diagrams and don’t put everything into onediagram
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 18 / 65
From Requirements to Design: CRC Cards
Activities in Software Developement
Understand and document what kind of the software the customerwants→ Requirements Analysis
Determine how the software is to be built→ Design
Build the software→ Implementation
Validate that the software solves the customers problem→ Testing→ Verification→ Evaluation: e.g. User friendlieness
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 20 / 65
From Requirements to Design: CRC Cards
From Requirements to Design: Solution
Design process1 The terms in the glossary give first candidates for classes,
attributes, and operations2 Take one use cases
a Take one main or alternative scnearioi Realize that scenario by adding new classes, attributes, associations,
and operations so that you design can execute that scenario(ii implement the design) (in case of an agile software development
process)
b Repeat step a with the other scenarios of the use case
3 Repeat step 2 with the other use cases
Techniques that can be usedGrammatical analysis of the text of the scenario→ nouns are candidate for classes and attributes; verbs are candidates
for operations, and adjectives are candidates for attributesCRC cards (= Class Responsibility Collaboration cards)
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 21 / 65
From Requirements to Design: CRC Cards
Introduction CRC Cards
CRC cards were developed by Ward Cunningham in the late 80’sCan be used for different purposes
Analyse a problem domainDiscover object-oriented designs
Learn to think objects→ Objects
have structure and behaviour→ both need to be considered at the same time
Literaturehttp://c2.com/doc/oopsla89/paper.htmlMartin Fowler: UML Destilled pages 62—63
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 22 / 65
From Requirements to Design: CRC Cards
CRC Card
ClassCan be an object of a certain typeCan be the class of an objectCan be a component of a systemIndex cards are used to represent classes (one for each class) (Iuse A6 paper instead of index cards)
ResponsibilitiesCorresponds roughly to operations and attributesSomewhat larger in scope than operations”do something””know something”
CollaborationsWith whom needs this class to collaborate to realize itsresponsibilities
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 23 / 65
From Requirements to Design: CRC Cards
CRC Card Template
A larger examplehttp://c2.com/doc/crc/draw.html
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 24 / 65
From Requirements to Design: CRC Cards
Process I
Starting pointList of use-cases scenarios
Should be as concrete as possible
A group of up to 2–6 peopleBrainstorming
Initial set of Classes (just enough to get started)Assign Classes to persons
Execute ScenariosSimulate how the computer would execute the scenarioEach object/class is represented by one personThis person is responsible for executing a given responsibility
This is done by calling the responsibilities of other objects/persons hecollaborates with
objects/classes can be createdresponsibilitites can be addedcollaborations can be added
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 25 / 65
From Requirements to Design: CRC Cards
Library Example: Detailed Use Case Check Out Book
Name: Check Out BookDescription: The user checks out a book from the libraryActor: UserMain scenario:
1 A user presents a book for check-out at the check-out counter2 The system registers the loan
Alternative scenarios:The user already has 10 books borrowed
2a The system denies the loanThe user has one overdue book
2b The system denies the loan
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 26 / 65
From Requirements to Design: CRC Cards
Example II
Set of initial CRC cardsLibrarien
The object in the system that fulfills User requests to check out, checkin, and search for library materials
BorrowerThe set of objects that represent Users who borrow items from thelibrary
BookThe set of objects that represent items to be borrowed from the library
Use case Check out book main scenario”What happens when Barbara Stewart, who has no accrued fines andone outstanding book, not overdue, checks out a book entitledEffective C++ Strategies+?”
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 27 / 65
From Requirements to Design: CRC Cards
Library Example: All CRC cards
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 29 / 65
From Requirements to Design: CRC Cards
Process: Next Steps
Review the resultGroup cards
by collaborationsshows relationship between classes
Check responsibilitiesCheck correct representation of the domainRefactor if needed
Transfer the resultUML class diagrams
Responsibilities map to operations and attributes/associationsCollaborations map to associations and dependencies
The executed scenarios to UML interaction diagrams
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 30 / 65
From Requirements to Design: CRC Cards
Example: Class Diagram (so far)
0..1 *
Borrower
canBorrow
Book
isOverduecheckOut(b:Borrower)calculateDueDate
Librarien
checkOutBook(b:Book)
Date
compare(d:Date)
* *
0..1 dueDate
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 31 / 65
From Requirements to Design: CRC Cards
Example: Sequence Diagram for Check-out book
Check Out Book Realization
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 32 / 65
From Requirements to Design: CRC Cards
Summary
Further scenarios give more detailThe scenarios are now quite easy to implementCRC process can be repeated on a more detailed level, e.g., todesign the database interaction, or user interfaceHelps one to think in objects (structure and behaviour)Humans playing objects help to get a better object-oriented designas it helps delegating responsibilities
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 33 / 65
Sequence Diagrams
Interaction Diagrams
PurposeDescribes how objects collaborate in some behaviour
TypesSequence Diagrams
1990’s: Message Sequence Charts (MSCs) used in TelCo-industry
Communication DiagramsTiming Diagrams
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 35 / 65
Sequence Diagrams
Example Sequence Diagrams
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 36 / 65
Sequence Diagrams
Example Communication Diagrams
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 37 / 65
Sequence Diagrams
Use of Sequence Diagrams
Usually a single scenarioBut can be extended to include several interactions
→ Executable UML / UML as a programming languageClass/object interactions
Express message exchange between objectsDesign message exchangeGet an overview of existing systems
Use Case ScenariosIllustrate a concrete scenario of a use caseUseful for design/documentation (Analysis, design, andreengineering)
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 38 / 65
Sequence Diagrams
Sequence Diagram Concepts
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 39 / 65
Sequence Diagrams
Creation and deletion of participants
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 40 / 65
Sequence Diagrams
Arrow types
a:A b:B
async call
sync call
return
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 41 / 65
Sequence Diagrams
Interaction Frames Example
Realising an algorithm using a sequence diagram
public void dispatch() {for (LineItem lineItem : lineItems) {if (lineItem.getValue() > 10000) {careful.dispatch();
} else {regular.dispatch();
}}if (needsConfirmation()) {messenger.confirm();
}}
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 42 / 65
Sequence Diagrams
Realisation with Interaction Frames
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 43 / 65
Sequence Diagrams
Interaction Frame Operators I
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 44 / 65
Sequence Diagrams
When to use sequence diagrams
Useful to visualize complex interactions between objectsVisualize the control flow in an object-oriented systemReverse Engineering but also Forward Engineering
Useful to describe Use Case scenariosSequence diagrams are less useful for describing algorithms→ Use state machines to show the behaviour of a single object across
several scenarios→ Use activity diagrams to show the behaviour of across many
objects and threads
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 45 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Computing the price of an order
TaskCalculate the price of an orderTake into account if the customer has any discounts
Order
calculate pricecalculate base pricecalculate discounts
Productnameprice
Customernamediscount info
OrderLinequantity
*
1
1
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 47 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Computation is concentrated in one class (centralisedcontrol)
The order computes the price by asking its collaborators aboutdata
→ centralised controlc©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 48 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Centralised Control: Class diagram
Order
calculate pricecalculate base pricecalculate discounts
Productnameprice
Customernamediscount info
OrderLinequantity
*
1
1
Only class Order has any interesting behaviourOrderLine, Customer, and Product are purely data classes (nomethods)
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 49 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Computation is distributed among several objects(distributed control)
The order computes the price by delegating part of the pricecalculation to order line and customer
→ distributed controlc©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 50 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Distributed Control: Class diagram
Order
calculate pricecalculate base pricecalculate discounts
Productnamepriceget price for quantity
Customernamediscount infocalculate discount
OrderLinequantitycalculate price
*
1
1
More customer types can beaddedEach computing the discountdifferently
The product nowcalculates the pricedepending on quantityOne could now haveproducts that arecheaper the more onebuys
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 51 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Design for change (I): Centralized Control
centralized control
B CA
m 0m1(B)m2(C)m3(D)
D
public class A {private B b;private D d;public void m0() {
m1(b);C c = getC();m2(c);m3(d);
}public void m1() {...}public void m2() {...}public void m3() {...}
}
Question: How easily can m0 be
adapted?
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 52 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Design for change (II): Distributed Control
distributed control
A
m 0
B
m1(A)m2(A)
D
m3(A)
C
m2(B)
public class A {private B b;private D d;public void m0() {
b.m1(this);b.m2(this);d.m3(this);
}}public class B {
private C c;public void m2(A a) {
c.m2(this);}
}
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 53 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Design for change (III): Distributed Control
distributed control
A
m 0
B
m1(A)m2(A)
D
m3(A)
C
m2(B)
B1
m1(A)m2(A)
D1
m3(A)
The behaviour of m0 can beadapted by using newsubclasses of A, B, C, and DThe subclasses have each theirown version of m0, m1, m2, andm3
What happens if a newsubclass, e.g. D2, is added?New subclasses can be easilyadded to adapt the behaviour,without m0 having to change
→ The system can be used andadapted to situations which onehas not thought of in thebeginning
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 54 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Design for change (IV): Centralized Control
m0 has to deal itself with allpossible subclasses
→ use of instanceofWhat happens if a newsubclass, e.g. D2 is added tothe system?
→ m0 has to change
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 55 / 65
Object-orientation: Centralized vs DecentralizedControl/Computation
Centralised vs Distributed Control
Centralised controlOne method does all the workThe remaining objects are merely data objects and usually don’thave their own behaviourTypical for a procedural programming style
Distributed controlObjects collaborate to achieve one taskEach object in a collaboration has behaviour (= is a ”real” object)Typical object-oriented style
Each object has its own responsibilitiesCreates adaptable designs
Object-OrientationDistributed Control is a characteristic of object orientation
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 56 / 65
Summary
Summary
Activity DiagramsFrom requirements to design: CRC cardsSequence DiagramsObject Orientation: Centralized vs Decentralized control
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 58 / 65
Summary
Software Engineering I (02161)Week 5
Assoc. Prof. Hubert Baumeister
Informatics and Mathematical ModellingTechnical University of Denmark
Spring 2011
c©2011 H. Baumeister (IMM) Software Engineering I (02161) Spring 2011 64 / 65