Systems Analysis & Design Methods UML diagrams. 2 System Analysis & Design Methods: UML diagrams...
-
Upload
kristopher-curtis -
Category
Documents
-
view
258 -
download
8
Transcript of Systems Analysis & Design Methods UML diagrams. 2 System Analysis & Design Methods: UML diagrams...
2System Analysis & Design Methods: UML diagrams
BooksBooks
UML for JAVA ProgrammersUML for JAVA Programmers(Robert C. Martin © Copyright 2003.)(Robert C. Martin © Copyright 2003.)
A book you A book you shouldshould read, even if it is not read, even if it is not necessary for this course.necessary for this course.
UML distilledUML distilledMartin FowlerMartin Fowler
3System Analysis & Design Methods: UML diagrams
ContentsContents
Normalized data model (not UML)Normalized data model (not UML) Class Model, conceptual (very useful)Class Model, conceptual (very useful) Class Model, design (very useful)Class Model, design (very useful) Object Model (useful)Object Model (useful) Sequence DiagramSequence Diagram State diagram (very useful)State diagram (very useful) Collaboration diagrams (very useful)Collaboration diagrams (very useful) Using Collaboration diagrams Using Collaboration diagrams (very (very
useful)useful)
4System Analysis & Design Methods: UML diagrams
Just to compare with class Just to compare with class model:model:
normalized relational normalized relational database model (Not part of database model (Not part of
UML)UML)
Customer
name
address
CompanyCustomer
PrivateCustomer
Product
nameprice
OrderedItem
quantity
*
1
Order
date
*
1
*
1
0..1 0..
1
1 1
?
PK customer_id
FK customer_id
FK customer_id
FK customer_idPK order_id
PK product_id
FK order_id
FK product_id}PK
5System Analysis & Design Methods: UML diagrams
RemarksRemarks
I haven’t given the usual ERD I haven’t given the usual ERD diagram diagram notationnotation..Instead, I follow these rules:Instead, I follow these rules: Arrows start from the foreign key Arrows start from the foreign key
and end with the primary key.and end with the primary key. Why ?Why ? This way, the databasemodel can This way, the databasemodel can be directly compared to the OO class be directly compared to the OO class model. It also makes clear that the model. It also makes clear that the many-to-one-relations are realized using many-to-one-relations are realized using a field that sits on the many-side and a field that sits on the many-side and identifies the identifies the oneone side. Not vice-versa. side. Not vice-versa.
6System Analysis & Design Methods: UML diagrams
RemarksRemarks All my arrows go upAll my arrows go up
Why ?Why ? This way, because the arrows go from This way, because the arrows go from the foreign key to the primary key, the the foreign key to the primary key, the many many side –if there is one- is always lower than the side –if there is one- is always lower than the one-side.one-side.
Also, Also, the entity/table that is dependend is the entity/table that is dependend is always lower than the entity/table it depends always lower than the entity/table it depends onon..
This way, dependencies and (most) cardinalities This way, dependencies and (most) cardinalities can be derived at a glance. -> No arrow-can be derived at a glance. -> No arrow-staring nor diagram-deciphering required. staring nor diagram-deciphering required.
7System Analysis & Design Methods: UML diagrams
RemarksRemarks
I do not show…I do not show…In order to be able to compare to the UML
class model, certain details, that are part of ER-diagrams are not shown:
…Relationship-types Identifying Non identifying Informative
8System Analysis & Design Methods: UML diagrams
Differences with Class Differences with Class models at models at
specification/implementaiospecification/implementaion leveln level Every field is supposed to be persistent.Every field is supposed to be persistent.
Pointers/Navigatabilities are always UNIdirectional.Pointers/Navigatabilities are always UNIdirectional. One to many relationships always point to the one-One to many relationships always point to the one-
side.side. The other way around would brake first normal form.The other way around would brake first normal form.
Normalization demands ‘no data redundancy’ nor Normalization demands ‘no data redundancy’ nor calculated fields. (OO specification/implementation calculated fields. (OO specification/implementation level class models would allow private redundant level class models would allow private redundant attributes e.g. for cashing)attributes e.g. for cashing) E.g. no orderPrice field in order !!!E.g. no orderPrice field in order !!!
No process/methods/procedures/functionsNo process/methods/procedures/functions E.g. no getOrderPrice method !!!E.g. no getOrderPrice method !!!
Possible sub-type tables (if allowed) cannot exploit Possible sub-type tables (if allowed) cannot exploit polymorphismpolymorphism
9System Analysis & Design Methods: UML diagrams
Class DiagramClass Diagram
Class diagrams are static. This Class diagrams are static. This means they are independent of the means they are independent of the moment in runtime. E.g. even if you moment in runtime. E.g. even if you might have hundreds of orders for might have hundreds of orders for one customer, you would still draw one customer, you would still draw just one class diagram ‘Order’. just one class diagram ‘Order’.
10System Analysis & Design Methods: UML diagrams
Class DiagramClass Diagramconceptualconceptual level level
Customer
+creditRating:String
-name-adress
CompanyCustomer
+billForMonth(int)
PrivateCustomer
-contact
Product
+getPrice():double
-name-price
OrderedItem
+getOrderedItemPrice():double
-quantity
*
1
Order
+getOrderPrice:double
-date
*
1
*
1
Association
Attributes
Multiplicity –or- Cardinality
Generalization
Method
11System Analysis & Design Methods: UML diagrams
Class DiagramClass Diagramspecification specification levellevel
Customer
+creditRating:String
-name-adress
CompanyCustomer
+billForMonth(int)
PrivateCustomer
-contact
Product
+getPrice():double
-name-price
OrderedItem
+getOrderedItemPrice():double
-quantity
*
1
Order
+getOrderPrice:double
-date
*
1
*
1
*
Navigatability
12System Analysis & Design Methods: UML diagrams
Class DiagramClass Diagramspecificationspecification levellevel
‘‘Specification’ means ‘Design’Specification’ means ‘Design’
You make design decisions. You make design decisions.
The arrowheads show which class has the The arrowheads show which class has the attribute pointing to the other(s). An attribute pointing to the other(s). An association with a navigatability in 1 association with a navigatability in 1 direction is called: unidirectional direction is called: unidirectional association. association. E.g. A customer points to many orders means:E.g. A customer points to many orders means:
Each Customer object will have a List attribute Each Customer object will have a List attribute of Order-objects (rather than than each Order-of Order-objects (rather than than each Order-object has a Customer-attribute)object has a Customer-attribute)
13System Analysis & Design Methods: UML diagrams
Class DiagramClass Diagramspecificationspecification levellevel
OrderedItem
+getOrderedItemPrice():double
Order
+getOrderPrice:double *1
OrderedItem
+getOrderedItemPrice():double
Order
+getOrderPrice:double *1
OrderedItem
+getOrderedItemPrice():double
Order
+getOrderPrice:double *1
-orderedItems: List
-order: Order
Design solution n° 1
Design solution n° 2
Conceptual
14System Analysis & Design Methods: UML diagrams
Class DiagramClass Diagramspecificationspecification levellevel
Navigatablitities are important. With design solution Navigatablitities are important. With design solution n°2, the functionality of the following code in n°2, the functionality of the following code in Order would be hard to write. Thanks to right Order would be hard to write. Thanks to right navigatability, I can delegate to OrderedItem: navigatability, I can delegate to OrderedItem:
public class Order{ public class Order{
… …
public double getOrderPrice(){public double getOrderPrice(){
double orderPrice = 0; double orderPrice = 0;
OrderedItem oItem;OrderedItem oItem;
for(int i = 0; i < orderedItems.size(); i++){for(int i = 0; i < orderedItems.size(); i++){
oItem = (OrderdItem) orderedItems.get(i);oItem = (OrderdItem) orderedItems.get(i);
orderPrice += oItem.getOrderedItemPrice(); orderPrice += oItem.getOrderedItemPrice();
}}
return orderPrice;return orderPrice;
}}
… …
}}
15System Analysis & Design Methods: UML diagrams
Object DiagramObject Diagram
Object diagrams are dynamic. This Object diagrams are dynamic. This means they depend on the moment means they depend on the moment of time during the system run. At of time during the system run. At implementation level, they are a implementation level, they are a snapshot of memory. E.g. if at a snapshot of memory. E.g. if at a certain moment in time a customer certain moment in time a customer record has 42 orders and you want record has 42 orders and you want to model this, you should draw 42 to model this, you should draw 42 order rectangles. order rectangles.
16System Analysis & Design Methods: UML diagrams
Object DiagramObject Diagram
:PrivateCustomer
-name = “Scott”
:Order
-date = 1/1/2003 :Order
-date = 1/5/2003 :Order
-date = 20/1/2001
orders.get(0) orders.get(1) orders.get(2)
Link
:OrderedItem
-quantity=2 :OrderedItem
-quantity=3 :OrderedItem
-quantity=10
:OrderedItem
-quantity=250
…orderedItems.get(0)orderedItems.get(1)orderedItems.get(2)
orderedItems.get(0)
:Product
-name= “Dell Dim 2.0”-price = 1000.0
product
:Product
-name= “Compac X2”-price = 2000.0
productproduct
17System Analysis & Design Methods: UML diagrams
Sequence DiagramSequence Diagram
:OrderItem
time
getOrderedItemPrice()getOrderedItemPrice()
:Product
getPrice()getPrice()
:double
:double
:Order
Loop
Data token
Activation
18System Analysis & Design Methods: UML diagrams
Sequence Diagram Sequence Diagram (continued)(continued)
[[topNode==nultopNode==null]l]
[topNode![topNode!=null=null]]
:TreeMap
add(key,value)add(key,value)
Guard
19System Analysis & Design Methods: UML diagrams
Sequence diagram Sequence diagram (continued)(continued)
Sequence diagrams are generally Sequence diagrams are generally harder to understand than the code harder to understand than the code they try to model, especially when they try to model, especially when loops and conditions are involved.loops and conditions are involved.
20System Analysis & Design Methods: UML diagrams
State Diagram (FSM)State Diagram (FSM)
ReadingNormalCodeReadingNormalCode
ReadingStringReadingStringDoubleQuoteEncountered/DoubleQuoteEncountered/StartWritingStringStartWritingString
DoubleQuoteEncountered/DoubleQuoteEncountered/SaveWrittenStringSaveWrittenString
NonDoubleQuoteEncountered/NonDoubleQuoteEncountered/AppendToStringAppendToString
StartStart
NonDoubleQuoteEncountered/NonDoubleQuoteEncountered/AppendToStringAppendToString
Event Action
State
Transition
21System Analysis & Design Methods: UML diagrams
:Button
Collaboration diagramCollaboration diagram
:Button
send:Button
:Dialer :Radio
:Screen :Speaker
Example taken from UML for Java programmersRobert C. Martin (2003). The letter A means ‘separate process‘
1*:digit(n)
1.1:displayDigit(n)1.2:tone(n)
2.1:connect(pno)
A1: inUse
2: Send
22System Analysis & Design Methods: UML diagrams
using a Collaboration using a Collaboration DiagramDiagram
Class diagrams can be used as a basis Class diagrams can be used as a basis for implementation. for implementation.
We build class diagrams in small steps:We build class diagrams in small steps: Take a part of the problem (e.g. a use Take a part of the problem (e.g. a use
case)case) Build a collaboration diagram in a step by Build a collaboration diagram in a step by
step fashion. step fashion. Extract a class diagramExtract a class diagram Improve the design (not shown)Improve the design (not shown)
23System Analysis & Design Methods: UML diagrams
using a Collaboration using a Collaboration DiagramDiagram
Example problem: Software that Example problem: Software that controls a celular phone.controls a celular phone.
Example Example partpart of the problem: ‘making of the problem: ‘making the phone call.’ the phone call.’ (adapted from UMLFJP R.C. (adapted from UMLFJP R.C. Martin )Martin )
24System Analysis & Design Methods: UML diagrams
using a Collaboration using a Collaboration DiagramDiagram
building the diagrambuilding the diagramHow do you start making a phone call ?How do you start making a phone call ?
You press a You press a buttonbutton with a digit on it. We imagine with a digit on it. We imagine some controlling piece of machinery capable of some controlling piece of machinery capable of dialing, that remembers the digits we entered, say dialing, that remembers the digits we entered, say a a dialerdialer..
:Button :Button :Dialer 1*:digit(n)
25System Analysis & Design Methods: UML diagrams
using a Collaboration using a Collaboration DiagramDiagram
building the diagram building the diagramAnything else happening when you press a Anything else happening when you press a
digit button ?digit button ?
Yes. The dialer needs to get the digit to be Yes. The dialer needs to get the digit to be displayed on displayed on screenscreen and maybe a sound to and maybe a sound to be emitted by a be emitted by a speakerspeaker..
:Button :Button :Dialer
:Screen :Speaker
1*:digit(n)
1.1:displayDigit(n)1.2:tone(n)
26System Analysis & Design Methods: UML diagrams
using a Collaboration using a Collaboration DiagramDiagram
building the diagram building the diagramYou keep on hitting digit buttons forever ? You keep on hitting digit buttons forever ? No.No.
Eventually you press the green phone Eventually you press the green phone button, lets say button, lets say send send button. You expect button. You expect the dialer to do what needs to be done. the dialer to do what needs to be done.
:Button :Button
send:Button
:Dialer
:Screen :Speaker
1*:digit(n)
1.1:displayDigit(n)1.2:tone(n)
2: Send
27System Analysis & Design Methods: UML diagrams
using a Collaboration using a Collaboration Diagram: building the Diagram: building the
diagramdiagramLets say the dialer delegates the work of ‘sending the phone Lets say the dialer delegates the work of ‘sending the phone number to the network’. It delegates this to a piece called number to the network’. It delegates this to a piece called radioradio..
When a connection is finally established, the screen might need When a connection is finally established, the screen might need to show an ‘in Use’ message.to show an ‘in Use’ message.
This is beyond the direct control of the cellular phone (different This is beyond the direct control of the cellular phone (different thread).thread).
:Button :Button
send:Button
:Dialer :Radio
:Screen :Speaker
1*:digit(n)
1.1:displayDigit(n)1.2:tone(n)
2.1:connect(pno)
A1: inUse
2: Send
28System Analysis & Design Methods: UML diagrams
using a Collaboration using a Collaboration Diagram:Diagram:
Deriving an initial class Deriving an initial class diagramdiagram
+digit(n:int)
+send
+tone(n:int)
+displayDigit(n:int)
+connect(pno:String)
Button
Speaker
Screen
Dialer Radio-lastpno:String*
Directions of messages becomes navigatabilitiesDirections of messages becomes navigatabilities Sent messages become methodsSent messages become methods Object counts becomes cardinalitiesObject counts becomes cardinalities