umldistilled
DESCRIPTION
uml distilledTRANSCRIPT
1
Page 1 © Martin Fowler 8/13/98
© Martin Fowler, 1998
Martin Fowler
[email protected]://ourworld.compuserve.com/homepages/Martin_Fowler
Page 2 © Martin Fowler 8/13/98
What We Will Cover (1)
q Background to UMLq Outline processq Grand Tour of Techniques
â Use Casesâ Class Diagramsâ CRC Cardsâ Both kinds of Interaction Diagramsâ Package Diagramsâ State Diagramsâ Activity Diagramsâ Design by Contract
http://ourworld.compuserve.com/homepages/Martin_Fowler
2
Page 3 © Martin Fowler 8/13/98
OO Methods
BoochBooch Rumbaugh / OMT
Rumbaugh / OMT
Jacobson / Objectory
Jacobson / Objectory
Odell / OOIEOdell / OOIE Shlaer / Mellor
Shlaer / Mellor
CoadCoad
Wirfs-Brock /RDD
Wirfs-Brock /RDDLate 80’s
early 90’s
Page 4 © Martin Fowler 8/13/98
Evolution of the UML
1988-92 Many analysis and design books1993 Standardization not a priority1994 Jim Rumbaugh joins Rational (Grady
Booch)1995 Booch/Rumbaugh unified method
released, Rational buys Objectory (IvarJacobson), OMG task force launched(chairs Mary Loomis and Jim Odell)
Jan 97 UML 1.0 submitted to OMG as proposalMid 97 OMG proposals unified behind UML 1.1Late 97 OMG adopts UML 1.1 as OMG UML 1.0Spr 98 OMG to issue UML 1.2 (minor changes)
3
Page 5 © Martin Fowler 8/13/98
Unified Modeling Language (UML)
q Developed by the three amigos: Booch,Jacobson and Rumbaugh at Rationalâ Many contributions through OMG process
q Notation and semantics, not processq Organizations preparing processes
â Rational: Objectory (Unified Process)â HP: Fusion
Fowler M with Scott K, UML Distilled:Applying the Standard Object ModelingLanguage, Addison-Wesley, 1997
www.rational.com/uml
Page 6 © Martin Fowler 8/13/98
UML Books
q Three amigos booksâ User Guide, Reference, and Unified Processâ End 98
q Fowler: UML Distilled, Addison-Wesleyâ Concise guide, assumes you know OO design
q Larman: Applying UML and Patterns, PrenticeHallâ Intro to Objects using UML
q Martin and Odell, OO Methods a Foundation,Prentice Hallâ Conceptual Modeling
q Douglass, Real-Time UML, Addison-Wesleyâ Real Time
4
Page 7 © Martin Fowler 8/13/98
Use-cases
q A use case is a typical interaction with thesystemâ Recognizable value to the user - meets a goalâ Testable
What would be some use cases for a WordProcessor?
http://members.aol.com/acockburn
Page 8 © Martin Fowler 8/13/98
Incremental Development
Cockburn A. Surviving Your Object-Oriented Project, Addison-Wesley, 1998
McConnell S. Rapid Development,Microsoft Press 1996
Goal: Reduce Risk
ExplorationDevelopment
1 2 ...
Finishing Finishing
5
Page 9 © Martin Fowler 8/13/98
Development
q Break into incrementsâ Build a few use-casesâ Analysis, design, implementation, testing, and
integrationâ Demo to user and verify functional tests for those
use-casesâ Step length 2 weeks to 2 months
q Do high risk and high priority use-cases firstq Time box the steps
â Cannot slip dates, may put off use-cases
Goal: Have clear milestones to measure progress
Goal: Tackle high risks early
Page 10 © Martin Fowler 8/13/98
Explorationq Gather use-cases
â One or two paragraphs
q Outline conceptual modelâ Find key abstractions in conceptual problem
q Baseline technical architectureâ Try out key pieces of technology and how they fit
togetherâ Determine key packages and interfaces
q About 1/5 of project length
Goal: Gain understanding to reduce risks in laterdevelopment
6
Page 11 © Martin Fowler 8/13/98
Dividing Use Cases
q Capture basic order informationâ Customer, date receivedâ Line items: quantity and product
q Price orderâ Rules vary with products, different price thresholds
and options.â May be combination rules
q Discount plansâ Customers may be members of various discount
plans.â Plans apply various discounts to ordersâ A particularly involved discount plan is the “bonnie
prince” plan
How many use cases here?
Page 12 © Martin Fowler 8/13/98
Granularity of Use Cases
Take Order
Take Order
Price Order
Customer Discounts
Bonnie PrinceDiscount Plan
Combination PricingRules
7
Page 13 © Martin Fowler 8/13/98
The «extends» Notion
q Simple case and variations
Take Order
Price Order Customer Discounts
Bonnie PrinceDiscount Plan
Combination PricingRules
«extends» «extends»
«extends»«extends»
Page 14 © Martin Fowler 8/13/98
Use-case Diagram
q Shows use cases and links between themâ Actorsâ Uses and extends
q Can be useful but not essential
Trading Manager
Trader
Salesman
Set Limits
Analyze Risk
Price Deal
Capture Deal
Limits Exceeded
Valuation
«extends»
«uses»
«uses»
ActorUse Case
8
Page 15 © Martin Fowler 8/13/98
Cockburn’s Style
q Base on the goal of a userq Consider main course scenario
â Everything goes well and goal succeedsâ Capture as sequence of steps
q Take each step in the use caseâ Ask what can go wrongâ Can we recover, if so howâ Each step may be another use case with its own
goal
q Capture variations in main courseq Note priority, time to be done in, and frequency
http://members.aol.com/acockburn
Page 16 © Martin Fowler 8/13/98
Abuse Cases
q Decompositionâ Temptation to drive designâ Takes time (for little value)
q Abstractionâ Loses usersâ Less value in testing
q GUI prototypesâ False sign of progressâ Encourages scope growth
q Denying choiceâ System v user use cases
Have you seen these traps?
9
Page 17 © Martin Fowler 8/13/98
Class Diagrams
Attributes
Operations
Association
Generalization
Class
OrderDate receivedisPrepaidNumberPrice
DispatchClose
Order Lineproductquantityprice
CustomerNameAddressCredit Rating
Corporate CustomerContact NameCredit RatingCredit LimitRemind
Personal CustomerCredit card #
]
]
1
1
{Orders for a customer with poorcredit rating must be prepaid}
Constraint
Page 18 © Martin Fowler 8/13/98
Modeling Perspectives
q Conceptualâ Describes people’s perception of the worldâ Independent of software
q Specificationâ Interfaces of classes (types)
q Implementationâ Internal features of a class
Cook, S. and Daniels, J. Designing Object Systems: object-oriented modeling with Syntropy, Prentice HallInternational, Hemel Hempstead, UK, 1994.
10
Page 19 © Martin Fowler 8/13/98
Association
q Defines connections between instancesâ Conceptual: employees must have a single
departmentâ Specification: you can ask an employee object for
its department (and change it)â Implementation: employee has a pointer to a
department
q Uni-directional and bi-directional
notationfor cardinalities
Skill1Department[ [
[
An employee must have a single department
Employee
Page 20 © Martin Fowler 8/13/98
GeneralizationA nurse is a kind of a person
q Conceptual: all nurses are peopleq Specification: (subtyping) nurse satisfies the
interface of person (substitutable)q Implementation: nurse is a subclass of person
(inherits data and behavior)
Person
Doctor Nurse
At what stages would you use whichperspective?
11
Page 21 © Martin Fowler 8/13/98
Dangers of Class Diagrams
q Emphasis on structure of classesâ May lead to data modelsâ De-emphasis on behaviorâ Lost in detailsâ Over-powerful abstractions
How can you tell when you have the rightmodel?
Page 22 © Martin Fowler 8/13/98
Class, Responsibility, Collaboration: CRC
q Developed by Ward Cunningham andKent Beck
q Informal techniqueq Concentrates on behavior, not data
OrderCheck Items are in StockDetermine the price Order LineCheck for valid payment CustomerDispatch to deliveryaddress
Order Line
12
Page 23 © Martin Fowler 8/13/98
Interaction (Sequence) Diagrams
q Many objects in one use-case
an Order an Order Line a Stock Item
a ReorderItem
an Order Entrywindow
* prepare()hasStock :=
check()
[hasStock]remove()
prepare()
[needsReorder] new
needsReorder :=needsToReorder()
a DeliveryItem
[hasStock] new
Message
Iteration
Condition
selfdelegation
creation
return
Object
deletion
Page 24 © Martin Fowler 8/13/98
Interaction (Collaboration)Diagrams
q Numbering shows sequenceq Control symbols
â * For iterationâ [ ] For condition
:Order Entry Window
:Order
talisker line : Order Line talisker stock : Stock Item
: reorder item: Delivery Item
1:prepare()
1.1*[for all orderlines]: prepare ()
1.1.1: hasStock := check ()1.1.2:[hasStock] remove ()
1.1.2.1: needsReorder :=needToReorder ( )
1.1.2.2: [needsReorder] new1.1.3:[hasStock] new
Object
messagesequencenumber
selfdelegation
Which form would youuse?
13
Page 25 © Martin Fowler 8/13/98
Key Books for Base Techniques
q Implementation focus: Booch, G. Object-oriented Analysis and Design WithApplications, (Second Edition), Benjamin /Cummings, Redwood City, CA, 1993.
q Conceptual Focus: Martin, J. And Odell, J.Object Oriented Methods: a Foundation, (UMLEdition) Prentice Hall, Englewood Cliffs, NJ,1998).
q For Responsibilities: Wirfs-brock R, WilkersonB and Wiener L (1990) Designing Object-oriented Software, Prentice Hall, EnglewoodCliffs NJ.
Page 26 © Martin Fowler 8/13/98
Patterns
q Patterns are the key to going beyond thebasics
q “Gang of Four” bookq Pattern Languages of Programming (PLoP)
conference
http://www.hillside.net/patterns
…projects fail despite the latesttechnology for lack of ordinarysolutions.
Ralph Johnson and Ward Cunningham
14
Page 27 © Martin Fowler 8/13/98
Design Pattern: Proxy
q Provide a surrogate or placeholder for anotherobject to control access to it
Gamma, E., Helm, R., Johnson, R. and Vlissides, J. DesignPatterns: elements of reusable object-oriented software, Addison-Wesley, Reading, MA, 1995.
Real Subject
request()Proxy
request()
Subject
request()
realSubject.request()
1
Page 28 © Martin Fowler 8/13/98
Analysis Patterns
q Prices of instruments change over timeq Hypothetical combinations of pricesq Prices of one instrument can affect others
Create a scenario to capture the real orhypothetical state of the market.
Instrument ScenarioElement
Scenario Timepoint
Money
[
1
1
1
1
[
[
[
15
Page 29 © Martin Fowler 8/13/98
Packages
q Classes grouped into packages (categories)q Dependency (visibility) relationships
between packagesq Classes within package marked public or
private
Martin, R.C. DesigningObject-Oriented C++Applications Using theBooch Method, PrenticeHall, Englewood Cliffs,NJ, 1995.
StocksDatabase
Package
Dependency
StocksPricer
StocksPricer UI Portfolio UI
PortfolioApplication
PositionsScenarioManager
GUI Library
Page 30 © Martin Fowler 8/13/98
Harel Statechart
q Single object in many use-cases
Wait
Catch exit / hide lock
Lock
Open
entry / release killer rabbit
Final
H
Active
candle removed [door closed] door opened
catch released / reveal lock
key turned [candle out]
key turned [candle in]
close safe
H
16
Page 31 © Martin Fowler 8/13/98
Simple Activity Diagram
q Similar to a flow chartReceive Order
Assign Goods toOrder
AuthorizePayment
Cancel Order
Dispatch Order
H
[suceeded]
[failed]
Page 32 © Martin Fowler 8/13/98
Decision Notation
q More similar to flowchart notationReceive Order
Assign Goods toOrder
Cancel Order
Dispatch Order
H
[payment authorized]
[payment rejected]
17
Page 33 © Martin Fowler 8/13/98
Introducing Parallel Behavior
q Sequence is independent
Receive Order
Assign Goods toOrder
AuthorizePayment
Cancel Order
Dispatch Order
H
[failed]
[suceeded]
Page 34 © Martin Fowler 8/13/98
Adding Iteration
q Iteration also occurs in parallel
Receive Order
Assign Goods toItem
AuthorizePayment
Cancel Order
Dispatch Order
H
[failed]
*[for each line item]
[stock assigned to all items and payment authorized]
[suceeded]
Reorder Goods
[need to reorder]
18
Page 35 © Martin Fowler 8/13/98
Multiple Diagrams (1)
q Order could be held up for stock
Receive Order
Assign Goods toItem
AuthorizePayment Cancel Order
Dispatch Order
H
[failed]
*[for each line item]
[stock assigned to all items and payment authorized]
[suceeded]
Reorder Goods
[need to reorder]
Check Line Item
[in stock]
Page 36 © Martin Fowler 8/13/98
Multiple Diagrams (2)
q May also lead to dispatch order
ReceiveIncoming Goods
Chooseoutstandingorder items
Assign Goods toItem
*[for each chosen item]
[all chosen items assigned]
Add Remainderto Stock
H
Dispatch Order
[stock assigned to allitems and payment authorized]
19
Page 37 © Martin Fowler 8/13/98
Combining Diagrams
Receive Order
Assign Goods toItem
AuthorizePayment
Cancel Order
Dispatch Order
H
[failed]
*[for each line item]
[stock assigned to all items and payment authorized]
[suceeded]
Reorder Goods
[need to reorder]
Check Line Item
[in stock]
ReceiveIncoming Goods
Chooseoutstandingorder items
Assign Goods toItem
*[for eachchosen item]
[all chosenitemsassigned]
Add Remainderto Stock
H
Page 38 © Martin Fowler 8/13/98
Design by ContractSquare Root
q Inputsâ x : Real Number
q Outputâ result : Real Number
q Pre-conditionâ x 0
q Post-conditionâ result * result == x
q Exceptionsâ none
Meyer, B. Object-Oriented Software Construction,Prentice-Hall, New York, 1996
Meyer, B. “Applying “Design by Contract”,” IEEEComputer, 25,10, (1992), pp. 40–51.
www.eiffel.com
o Also uses classinvariants
20
Page 39 © Martin Fowler 8/13/98
CASE Tools
Evaluate what you are getting
q Design Documentâ Drawing facilitiesâ Repository reportsâ Uses right set of UML for you?â Selectivity
q Code Generationâ Can you work with the code?â Updated code fed back into model?
What is your favorite CASE tool?
Page 40 © Martin Fowler 8/13/98
Translation
q Advocated by Shlaer/Mellorâ Basic idea also used by ObjectTime
4 Easy regeneration of system to differentplatforms
4 Can reuse the archetypes8 Does it work in practice?
Domain Analysis
Archetypes
Model Compiler Final System
Capturespecifics of
domain
Rules for yourplatform
21
Page 41 © Martin Fowler 8/13/98
Why use these techniques?
q Start small, add notation as neededq Experiment with different things
â throw away what does not workâ different teams have different needs
q UML can communicate with programmers anddomain experts
Page 42 © Martin Fowler 8/13/98
A method is not enough
q Using a method will not make or break yourproject
q The choice of training and mentoring will makeor break your project