CO817 2008
25
Three different kinds of object diagram
Class diagrams – show static relationships between classes.
Communication diagrams – show communication patterns between objects. Sequence diagrams – use the vertical dimension to represent time and show detailed communication between small numbers of objects.
CO817 2008
26
Class Diagrams
Used to model static objects and the relationships between them.
Feature in just about every OO software design methodology. Show objects as boxes and relationships as lines with annotations and possible arrow heads.
CO817 2008
27
A typical class diagram (from Fowler)
CO817 2008
28
Perspectives
There are three perspectives that can be used in class diagrams.
Conceptual – represents the problem domain and is created in order to analyse and understand it. (also called a domain model) Specification – boxes in the diagram represent software objects but not to the level of programming language implementation
Implementation – shows real classes in the implementation language (e.g. Java) Can start off with a domain model and refine it into an design model.
CO817 2008
29
Kinds of relationship
Associations
an order has a customer who initiated it and will take delivery
Subtypes
A corporate customer is a kind of customer
CO817 2008
30
Associations
Represent relationships between instances of classes.
Can be annotated with multiplicities
a customer can have zero or more orders but each order is associated with just one customer.
An association can have an optional role, describing what the relationship is.
for example: sales rep in the example diagram
Arrows showing navigability
CO817 2008
31
Multiplicities
*
1..* T zero or more; "many"
T
one or more
1..40
T
one to 40
5
T
exactly 5
3, 5, 8
T
exactly 3, 5, or 8
CO817 2008
32
Navigability
Open arrow heads are used to show that an association is navigable.
For example, a sales order can be interrogated to determine the customer but not the other way round.
CO817 2008
33
Subclasses
These are shown using a large, open arrow head.
In the specification or implementation perspectives, represent class subtyping. In a domain model, show a subtype relationship between concepts.
CO817 2008
34
Domain Model
Described using class diagrams with a conceptual perspective.
Part of the requirements-capture part of a project.
understandable by the user classes can be developed into classes in a design model (with a specification or implementation perspective)
CO817 2008
35
Example Domain Model Diagram
co ce t n p o d m in r o a o je b ct S le a s L e m in Ite q a tity un 1* .. S cke -in to d a cia n sso tio C n in d o ta e -in 1 S le a a u s ttrib te d te a tim e 1 P id y a -b 1 P ym n a et a on mu t S re to a d ss d re nm a e 1 Hu s o se 1* .. Rg r e iste C p re -o a tu d n 1 1 0 ..1 R co s-sa -o e rd le f 1 Ite m
*
0 ..1
CO817 2008
36
Domain Model to Design Model
U D m inM d l P o a oe S k h ld r'sv wo th n te o yc n e tsinth d m in ta e o e ie f e o w rth o c p e o a . AP y e t inth D m inM d l a mn e o a oe isac n e t, b t aP y e t in ocp u a mn th D s nM d l isas ftw re e e ig o e o a c s . T e a n t th s m la s h y re o e a e th g b t th fo e in p dth in , u e rm r s ire e n m ga dd fin no th a in n e itio f e la r. tte T isre u e th re re e ta n l h d c s e p s n tio a gp a. T isiso eo th b id a in h n f e ig e s o je t te h o g . b c c n lo y Py et a mn a o n Mn y m u t: o e g tB la c (): M n y e a ne oe 1 P y -fo as r 1 d te D te a : a s rtT e T e ta im : im g tT ta M n y e o l(): o e ... Py et a mn a on mu t in p s s ire o je ts b c ad n n m sin a e S le a S le a 1 P y -fo as r 1 d te a tim e
U D s nM d l P e ig o e T eo je t-o n dd v lo e h sta e in p tio fro th re l w rldd m in h b c rie te e e p r a k n s ira n m e a o o a inc a gs ftw rec s e . re tin o a la s s T e fo , th re re e ta n l g pb tw e h ws k h ld rsc n e eth h re re e p s n tio a a e e n o ta e o e o c iv e d m in a ditsre re e ta nins ftw re h sb e lo e d o a , n p s n tio o a , a e n w re .
CO817 2008
37
Finding Domain-model Classes
Reuse or modify existing models
Books of existing domain models exist.
Use a category list containing categories of things that are good candidates to be classes
e.g. roles of people, physical objects, containers of things.
Identify nouns and noun phrases in a description of the domain.
Verbs are good candidates for methods.
CO817 2008
38
A problem description
The cinema booking system should store seat bookings for multiple theatres. Each theatre has seats arranged in rows. Customers can reserve seats and are given a row number and seat number. They may request bookings of several adjoining seats. Each booking is for a particular show (i.e., the screening of a given movie at a certain time). Shows are at an assigned date and time, and scheduled in a theatre where they are screened. Thesystemstoresthecustomers’telephone number.
CO817 2008
39
Nouns and verbs
Cinema booking system Stores (seat bookings) Stores (telephone number)
Theatre Has (seats)
Movie
Customer Reserves (seats) Is given (row number, seat number) Requests (seat booking)
Show Is scheduled (in theatre) Telephone number
Time
Date
Seat booking Seat
Row
Seat number
Row number
CO817 2008
40
Communication diagrams
Lines between objects represent communications paths and are annotated with numbered messages.
1 aP e c h nrd : k a n aTde m y t s ee ) e m ( 2o :o f : e tr Rs ge i 2b .: a 1 r :a S l e
lke i l ni n
CO817 2008
41
Message sequence numbers
fir t s scn eo d th d ir mg s1 1 mg : s2
:A
:B 1 : mg .1 s 3 2 : mg .1 s 5
2 mg : s4
:C
fo r uth 2 : mg .2 s 6
fifth
s th ix :D
CO817 2008
42
Sequence Diagrams
Show sequences of input and output events
Can show events for a system component or for the whole system. System Sequence Diagrams (SSDs) are used to show use case scenarios in a diagrammatic form.
CO817 2008
43
Example SSD
Po e sS leS e aio r cs a cnr : C s ie ah r mk N w a a e e S le S p c s - n Po e sS les e aio imle a ho ly r c s a c n r : 1 C s mr ar e a aP Sc e k u . u to e r iv s t O hcot w g o sa d r s r ic stop r h s . ith o d n /o ev e uc a e 2 C s ie s r an w a . . a h r tats e s le 3 C s ie e tesite id n r . ah r n r m e tifie. 4 S s m e od s lelin ite a d . y te r c r s a e mn pe e tsite d s r tio , pic , a d r sn m e cip n r e n r n in to l. u n g ta C s ie r p a s p 34u til in ic te a h r e e ts te s - n d a s dn. oe 5 S s m r s n to l w ta e . y te pe e ts ta ith x s c lc la d a u te . 6 C s ie te C s mr th to l, a d . a h r lls u to e e ta n a k fo p y e t. s s r a mn 7 C s mr p y a dS s m a d s . u to e a s n y te h n le p y e t. a mn ... lo p o [ mr ite s] oe m e teIte ( m , q a tity n r m ite ID u n ) :S s m y te
d s r tio , to l e cip n ta
ed a n S le
to l w ta e ta ith x s
mk P y e t( mu t) a e a mn a o n
c a g d e r c ip h n e u , ee t
CO817 2008
44
Sequence diagram notation
Each participating object is shown as a veritcal line (called a lifeline) with a box at the top.
The lifeline is usually drawn dashed though it can be solid.
Time always goes downwards.
A lifelines can also contain vertical boxes called activation bars or execution specification bars, showing when the code in that object is active
CO817 2008
45
Example activation boxes
life eb xr pe e tin a lin o e r s n g n u n m din ta c o c s S le n a e s n e f la s a life eb xr pe e tin a lin o e r s n g n m din ta c a e s ne life eb xr pe e tin th c s lin o e r s n g e la s F n o m r pe is ly th t F n is o t, r oe r c e , a o t a in ta c o c s C s –a n s n e f la s la s n in ta c o am ta la s s ne f e c s
: a S le
s : S le 1 a
« ea la s mt c s » Fn ot
L t isa in r c is n tefa e life eb xr pe e tin a lin o e r s n g n in ta c o a Ar y is c s , s n e f n r a L t la s p r m teiz d( m la e ) to aa e r e te p tiz d h ldS leo je ts o a b c life eb xr pe e tin lin o e r s n g o ein ta c o c s S le n s n e f la s a , s le te fr m es le e c d o th a s Ar y is < a >c lle tio r a L t S le o c n inU L1 w c u n t u ea M .x e o ld o s n in r c h r , b t inU L2 th ( r tefa e ee u M , is o a a s a t c s ) isle a n b tr c la s gl
s le : a s Ar y is S le r a L t< a >
s le [ i ] : S le a s a
x: L t is
r la d e te ea p x m le
CO817 2008
46
Messages
: R g te e is r dX o dA o dB o dC o dD o : S le a
afo n m s a e ud esg w o es n e w n t h s e d r ill o b s e ifie e pc d
e e u ns e ific tio x c tio p c a n b r in ic te fo u o a d a s cs f cn l o tro
ty ic l s c r n u m s a e p a y ho o s e s g s o nw afille -a wlin h w ith d rro e
CO817 2008
47
Object Construction
:R i t r es ge
:Sl a e
nt t anw c a d o ht e l r t e y ee oj c a p cd tt e b t r l e a hi es e a r c ao " e h r t n hi t ei g"
m e am t csTne d a Py e ( ahedr ) k n e c a ( ahedr d r t csTne ) ee e :Py et am n
at oz u re hi
CO817 2008
48
Diagram Frames
Show conditional or looping constructs
:A m NS a e a k wl e e aM o U l p L o fae ih rm t a ,w b l ag r oe ud on a e rso xei n p s o tm r e ] l o [m ies o p
:B
eee(eI ,q ny nr m m u t ) t I t i t D ai t
d c t nol e r i ,t t si o a p
eS na dl e