Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Design Models
1. Goals and Scope 2. Principles of Visual Modeling 3. Outline of UML and Unified Process 4. Specification Requirements 5. Use-Case Models a. Use-Case Diagram b. Activity Diagram 6. Design Models a. Goals of design b. Interaction Diagrams i. Sequence Diagram ii. Communication Diagram iii. Timing Diagram iv. Interaction Overview Diagram c. State Machine Diagram d. Class Diagram 7. Implementation Diagrams
Tiberiu Leia : Software Engineering Analysis&Design
a. Goals of Design
Decompose the system into components (identify the software architecture) Describe the component functionality (formally or informally) Determine the relationships between components
o o
Decomposition divide the large system into smaller parts i. Select a part of the system ii. Determine the components in this part iii. Describe the component interactions iv. Repeat the steps i-iii until some terminations criteria is met
Component
- a software entity encapsulating the representation of an abstraction - it has an interface o output = export = services provided to other components o input = import = services required from other components - access control
b. Interaction
i. ii. iii. iv. Sequence Diagrams Communication Diagram Timing Diagram Interaction Overview Diagram
Diagrams
UML Object notation: ObjectName/ClassifierRoleName : ClassifierName[,ClassifierName] Combinations: :C unnamed instance from a class C /R unnamed instance playing the role R /R:C - unnamed instance from a class C playing the role R O/R instance named O playing the role R O/R:C instance named O from a class C playing the role R O instance named O / - unnamed instance, unnamed class, unnamed role
Tiberiu Leia : Software Engineering Analysis&Design
i. Sequence Diagram
User : Actor Object1 Object2
<<create>> 1 : Create()
2 : PerformResponsability()
Execution Occurrence
Event Occurrence
3 : selfStimulus()
4 : request()
<<destroy>> 9 : destroy()
8 : sendData
User
Browser
WebServer
<<create>> 3 : request(PageIdentifier)
4 : serchPage()
5 : sendPage
<<destroy>> 12 : dstroy()
A Sequence diagram describes interactions among objects. The interactions are represented in a chronological order. The sequence diagram contains the objects participating in the interaction and describes the messages they send. An object is represented as a vertical dashed line called the "lifeline." The lifeline represents the existence of the object during represented particular time. An object symbol is drawn at the head of the lifeline. The object represented at the start of the lifetime shows the name of the object and optionally its class separated by a colon. All are underlined. A message is a communication between objects that transports information. The message specifies the activity expected to be performed. It is represented as a horizontal solid arrow from the lifeline of one object to the lifeline of another object.
Tiberiu Leia : Software Engineering Analysis&Design
The reflexive message can be represented by arrow that starts and finishes on the same lifeline. The arrow is labeled with the name of the message and its parameters. The arrow may also be labeled with a sequence number. Execution Occurrence represents the relative time that the flow of control is performed in an object. Execution occurrence is shown as narrow rectangles on object lifelines. Event Occurrence represents the sending or receipt of messages. Interaction Occurrence is a reference to an interaction within the definition of another interaction. Hierarchical numbering is used for all messages on a dependent message. The dependent message is the message whose execution occurrence the other messages originate in. Notes describe the flow of events textually.
Tiberiu Leia : Software Engineering Analysis&Design
Representations - Notations: Synchronous call of a method ex. getValue(Parameters) Return from a call
10
ElevatorUser
RequestElevator
FullSensor
DispatchElevator
ControlElevator
ElevatorMotor
ArrivalSensor
1 : pressUp
2 : requestElevator(direction,floor) 3 : getState() 4
5 : addFloor(floor)
6 : startUp 7 : arrivalSignal The cage arrives at the requested floor. 8 : arrivalSignal 9 : stop
11
ElevatorUser
RequestElevator
FullSensor
DispatchElevator
ControlElevator
ElevatorMotor
ArrivalSensor
DoorMotor
1 : press(floor) 2 : insertList(floor) 3 : readState() 4 5 : close 6 : startUp The elevator is stationary and not full 7 : arrivalSignal 8 : arrivalSignal 9 : stop 10 : open The cage arrives at the requested floor.
12
Implementation
The destination object of the message (or signal) can be active or passive. The interaction can be: synchronous (call or signal) o the called object wait to be asked object synchronization o the called object wait to be notified object synchronization asynchronous (call or signal) o the destination object doesnt wait the interaction interruption. 1. How can asynchronous call of a method be implemented in Java? a. The object implementing the called method is passive. b. The object implementing the called method is active. It executes the run() method when the call arrives. It must be interrupted to execute something else. 2. How can asynchronous signal of an event be implemented in Java? a. The destination object of the signal is passive. Can it react? b. The destination object of the signal is active. It executes the run() method when the signal arrives. It must be interrupted and must execute something else.
Tiberiu Leia : Software Engineering Analysis&Design
13
14
ArrivalSensor
DoorMotor
15
16
17
Controller
Select
18
19
Two new elements are added: interaction occurrences are references to the existing interaction diagrams. It is shown as a reference frame. interaction elements are similar to interaction occurrences. They display a representation of existing diagrams within a rectangular frame. They display the contents of the references diagram inline.
20
seq sd InteractionOverview
21
22
State In computer science and automata theory, a state is a unique configuration of information in a program or machine. It comprises all the information necessary to determine the further evolution of the system for a given input. Transitions A transition describes a change from one state to another. It can be triggered by an event that is either internal or external to the modeled entity. A transition can be the result of the invocation of an operation that causes an important change of the entity state.
Tiberiu Leia : Software Engineering Analysis&Design
23
Actions and activity An action is an operation that is invoked by/on the entity. An activity is an operation or set of operations performed by entity when it is on a particular state. Events: Time Event Change Event Call Event Signal Event
24
Guards A guard is a condition that must be fulfilled (true) for the transition to be triggered and are optionally represented. Representation: trigger [guard]effect or trigger [guard]/list of methods trigger the cause of the transition guard - logic expression - free language expression effect operation(s) or action executed as effect of the transition it is automatically invoked by object when the transition occurs.
25
State2
SubmachineState1
26
Recommendations:
1. Name Software Actions Using Implementation Language Naming Conventions 2. Name Actor Actions 3. Indicate Entry Actions Only When Applicable For All Entry Transitions 4. Indicate Exit Actions Only When Applicable For All Exit Transitions 5. Model Recursive Transitions Only When You Want to Exit and Re-Enter the State 6. Name Transition Events in Past Tense 7. Place Transition Labels Near The Source State 8. Place Transitions Labels Based on Transition Direction. To make it easier to identify which label goes with a transition, place transition labels according to the following heuristics:
Above transition lines going left-to-right Below transition lines going right-to-left Right of transition lines going down Left of transition lines going up
Tiberiu Leia : Software Engineering Analysis&Design
27
State types: simple state composed state can be further modeled as a state submachine
28
S1 Init
Flow Final
ExceptionHandling
Ready
Fail Exception
Process
S3
S2
Fig. 1.z. Example of State Machine Diagram with end of flow and init state avoidance.
29
S1 Init
History State
Interrupt Handler Interrupt event
Ready H
Process
Save
A history state is used to remember the previous state of a state machine when it was interrupted.
S3
S2
30
Region 1 Init
S1 S1.1
S1.3
S1.2
S2.1.
S2.2
S2.3 Region 2
31
S1 S1.1
S1.3
S1.2
S2.2
Fig. 1.u. Example of State Machine Diagram with two regions and synchronization.
32
Join
Exception Handler
Choice Point
S3
S2
Fig. 1.z. Example of State Machine Diagram with Choice and Join pseudostate.
33
S1.1
synchronizedMethod()
S1.2
Lock Monitor
...........................................................................................................................
Unlock Monitor
S2.1
synchronizedMethod()
S2.2 Region 2
34
Region 1
Concurrent
WaitState
10 sec./mon.notify()
wait(10 sec.)
S1.2
mon.notified/
S2.2 Region 2
35
Region 1
Concurrent
Ready
/mon.notify()
mon.notified/ S1.2
mon.notified/
36
Request Wait
/dispatcher.notify() entry/get(floor,direction) do/chooseElevator exit/addFloor(elevator.list) ..................................................................................................................................................... Control Ready elevator.notified/[ListNotEmpty] MoveToNextFloor entry/readList() do/moveToFirstFloorInList [ListEmpty] Wait [ListNotEmpty] wait(30 sec.)
37
38
c. Class Diagram
A class diagram (model) represents a static view of the system or part of it. UML class diagrams shows the classes, their inter-relationships, the attributes and the operations of the classes. They are used to: explore the domain concepts conceptual class diagrams analyze the requirements detail the design design class diagrams A class has attributes and behavior. The behavior is given by the possible messages the class is able to understand. The instance of the class reacts with appropriate operation for each message.
Tiberiu Leia : Software Engineering Analysis&Design
39
Classes may have defined: constraints, tagged values and stereotypes. The visibility of elements is denoted by: + public - private # protected ~ package visibility
40
Elements of Class Diagrams Aggregation light aggregation strong aggregation = composite aggregation Light aggregation ClassA uses ClassB ClassA not necessarily contains an instance of ClassB.
Target Source
ClassA
+1..*
ClassB
Light Aggregation
If an object of ClassA is not necessarily the owner of an instance of ClassB, then the last can be included in different instances of ClassA. The instance of ClassA and the instance of ClassB dont have necessarily the same lifetime.
Tiberiu Leia : Software Engineering Analysis&Design
41
Strong, composite aggregation An instance of ClassA contains (owns) an instance of ClassB. They have the same lifetime. The instance of ClassA is responsible of creation of the instance of ClassB. If the instance of ClassA is deleted, the instance of ClassB is deleted too.
Target
Source
ClassA
ClassB
Strong Aggregation
42
Inheritance = Extension
SuperClass
Inheritance
43
Associations An association is a construct that allows a connection to have operations and attributes. unidirectional bidirectional aggregation association Associations allow the navigation.
ClassA
+role 1 +0..*
ClassB
Class associations
44
Implementor +writeSource()
ExecutableCode
TestProgram +TestSource +TestReport DesignDiagrams +SequenceDiagram +CommunicationDiagram +TimingDiagram +InteractionOverviewDiagram +StateMachineDiagram +ClassDiagram Designer +drawSequenceDiagram() +drawCommunication() +drawTiming() +drawInteraction() +drawStateMachine() +drawClass() Tester +writeTestProgram() +writeTestResults()
45
Construction of design class diagrams = to iteratively model: classes responsibilities associations inheritance relationships compositions relationships interfaces
46
Class normalization (Scott W. Ambler) Class normalization is a process by which the structure of an object schema is organized such that to increase the cohesion of classes while the coupling between them is minimized. First Object Normal Form (1ONF) A class is in first object normal form (1ONF) when specific behavior required by an attribute that is actually a collection of similar attributes is encapsulated within its own class. An object schema is in 1ONF when all of its classes are in 1ONF. Second Object Normal Form (2ONF) A class is in second object normal form (2ONF) when it is in 1ONF and when shared behavior that is needed by more than one instance of the class is encapsulated within its own class(es). An object schema is in 2ONF when all of its classes are in 2ONF.
Tiberiu Leia : Software Engineering Analysis&Design
47
Third Object Normal Form (3ONF) A class is in third object normal form (3ONF) when it is in 2ONF and when it encapsulates only one set of cohesive behaviors. An object schema is in 3ONF when all of its classes are in 3ONF. Refactory It is disciplined way to restructure the code by implying small changes to the code with the goal to improve the design.
48
Steps for class diagram construction: 1. Identify responsibilities on domain class diagrams. 2. Indicate visibility only on design models. 3. Indicate language-dependent visibility with property strings. 4. Indicate types only on design models. 5. Indicate types on analysis models only when the type is an actual requirement. 6. Design class diagrams should reflect language naming conventions. 7. Model association classes on analysis diagrams. 8. Do not name associations that have association classes. 9. Center the dashed line of an association class.
49
Recommendations for representation of associations: 1. Model relationships horizontally 2. Collaboration indicates need for a relationship 3. Model a dependency when the relationship is transitory 4. Depict similar relationships involving a common class as a tree. 5. Always indicate the multiplicity 6. Avoid a multiplicity of * 7. Replace relationships by indicating attribute types. 8. Do not model implied relationships 9. Do not model every single dependency 10. Center names on associations 11. Write concise association names in active voice 12. Indicate directionality to clarify an association name 13. Name unidirectional associations in the same direction 14. Word association names left-to-right
Tiberiu Leia : Software Engineering Analysis&Design
50
15. Indicate role names when multiple associations between two classes exist 16. Indicate role names on recursive associations 17. Make associations bi-directional only when collaboration occurs in both directions. 18. Redraw inherited associations only when something changes 19. Question multiplicities involving minimums and maximums
51
Class Responsibility Collaborator CRC Model Set of cards Class Name Responsibilities Collaborators
52
Class Diagram
53
Request Inter1
+2
Select
+2 +state
ArriveSensorInterface Elevator
54
55