lab 6: uml - software engineering lab -...
TRANSCRIPT
CSE4006: Software Engineering
Lab 6: UML
Software Engineering Lab
Except where otherwise noted, the contents of this document are Copyright 2016 Gwanggyu Choi, Scott Uk-Jin Lee. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.
UMLUnified Modeling Language
• A general-purpose modeling language which is designed to provide standard way to visualize the design of a system.
• Maintained by the OMG (Object Management Group)
• http://www.omg.org
CRC Cards
Class-resoponsibility-colleboration Cards
• A brainstorming tool used in object-oriented design
• Proposed by Ward Cunningham and Kent Beck.
Class : Student
Responsibility Colleborator
goes to school does homework skip a class
Bus Computer
CRC Cards - ExampleCRC Modeling
CRC card
Scott Uk-Jin Lee CSE4006 Software Engineering
UML Diagrams
Class Diagrams
Class Diagram
• Description of static structure
• Showing the types of object in system and the relationships between them
• Foundation for the other diagrams
UML 2.0 Class Diagram
Class Diagrams
Description of static structureShowing the types of objects in a system and the relationshipsbetween them
Foundation for the other diagrams
Scott Uk-Jin Lee CSE4006 Software Engineering
Class Diagrams (cont)
Classes
• Description of a set of objects
• Abstraction of the entities
UML 2.0 Class Diagram
Classes
Most important building block of any object-oriented system
Description of a set of objects
Abstraction of the entities
Existing in the problem/solution domain
Scott Uk-Jin Lee CSE4006 Software Engineering
Class Diagrams (cont)Attributes
• Represent some property of the thing being modeled
• Syntax: attributeName : Type
Operations
• Implement of a service requested from any object of the class
• Syntax: operationName(param1:type, param2:type, …) : Result
UML 2.0 Class Diagram
Attributes & Operations
AttributesRepresent some property of the thing being modeledSyntax: attributeName : Type
OperationsImplement of a service requested from any object of the classSyntax: operationName(param1:type, param2:type, ...) : Result
Scott Uk-Jin Lee CSE4006 Software Engineering
+ : public - : private # : protected
Class Diagrams (cont)Association
• Relationship between classes that specifies connections among their instances
Multiplicity
• Number of instances of one class related to ONE instance of the other class
UML 2.0 Class Diagram
Association & Multiplicity
AssociationRelationship between classes that specifies connections amongtheir instances
MultiplicityNumber of instances of one class related to ONE instance ofthe other class
Scott Uk-Jin Lee CSE4006 Software Engineering
Class Diagrams (cont)Aggregation
• Weak “whole-part” relationship between elements
• e.g., An airport has many airplanes
Composition
• Strong “whole-part” relationship between elements
• e.g., Window ‘contains a’ scrollbar
UML 2.0 Class Diagram
Aggregation & Composition
Aggregation
Weak “whole-part” relationship between elementse.g., An airport has many airplanes
Composition
Strong “whole-part” relationship between elementse.g., Window ‘contains a’ scrollbar
Scott Uk-Jin Lee CSE4006 Software Engineering
Class Diagrams (cont)
Inheritance
• Relationship between superclass and subclasses
• All attributes and operations of the superclass are part of the subclasses
UML 2.0 Class Diagram
Inheritance
Relationship between superclass and subclassesAll attributes and operations of the superclass are part of thesubclasses
Scott Uk-Jin Lee CSE4006 Software Engineering
Class Diagrams (cont)Generalization
• Building a more general class from a set of specific classes
Specialization
• Creating specialized classes base on a more general class
UML 2.0 Class Diagram
Generalization & Specialization
GeneralizationBuilding a more general class from a set of specific classes
SpecializationCreating specialized classes base on a more general class
Scott Uk-Jin Lee CSE4006 Software Engineering
Class Diagrams (cont)Active class
• Own a thread control and can initiate control activity - used when asynchronous communication is necessary
- typically modeled with a state machine of its behavior
- encapsulated with ports and interfaces
Passive class
• created as part of an action by another object - own address space, but not thread of control
- executed under a control thread anchored in an active object
UML 2.0 Class Diagram
Active vs. Passive Class
Active classOwn a thread control and can initiate control activity- used when asynchronous communication is necessary- typically modeled with a state machine of its behavior- encapsulated with ports and interfaces
Passive classCreated as part of an action by another object- own address space, but not thread of control- executed under a control thread anchored in an active object
Scott Uk-Jin Lee CSE4006 Software Engineering
Class Diagrams (cont)
Ports
• Define an interaction point on a classifier with external environment
Interface
• Describe behavior of objects without giving their implementation - each class implements the operations found in the interface
UML 2.0 Class Diagram
Ports vs. Interfaces
PortsDefine an interaction point on a classifier with externalenvironment
InterfacesDescribe behavior of objects without giving theirimplementation- each class implements the operations found in the interface
Scott Uk-Jin Lee CSE4006 Software Engineering
Class Diagrams (cont)
Stereotype in UML
• UML extension mechanism
• enables users to define the meaning of special modeling element
• represented with double angle brackets
UML 2.0 Class Diagram
Stereotype in UML
UML extension mechanism
enables users to define the meaning of special modelingelementrepresented with double angle brackets
Scott Uk-Jin Lee CSE4006 Software Engineering
Class Diagrams (cont)Provided interface
• Class provides the services of the interface to outside callers
• what the object can do
• Provided interface accept incoming signal from outside callers
Required interface
• Class uses to implement its internal behavior
• What the object needs to do
• Outgoing signal are sent via required interface
UML 2.0 Class Diagram
Provided & Required Interface
Provided interface
Class provides the services of the interface to outside callersWhat the object can doProvided interface accept incoming signal form outside callers
Required interface
Class uses to implement its internal behaviorWhat the object needs to doOutgoing signal are sent via required interface
Scott Uk-Jin Lee CSE4006 Software Engineering
Tips for Class ModelingFinding Classes
• Do we have things that should be stored or analyzed?
• Do we have external system?
- external system is modeled as class
• Do we have any patterns, class libraries, components, etc?
• Are there devices that the system must handle?
Make explicit traceability whenever possible
• Try to capture class/attributes from nouns of use-cases and operations from verb of use-cases
• Always draw class diagram in conjunction with some form of behavioral diagrams
Class Diagrams - Example
Class Diagrams - Example
Class Diagrams - Example
State Machine Diagram
Describe the dynamic behavior of objects over time by modeling the lifecycles of objects of each class
• The event that cause a transition from one state to another
• The action that result from a state change
UML 2.0 State Machine Diagram
State Machine Diagram
Describe the dynamic behavior of objects over time bymodeling the lifecycles of objects of each class
The event that cause a transition from one state to another
The actions that result from a state change
Scott Uk-Jin Lee CSE4006 Software Engineering
State Machine DiagramEvent
• stimulus which causes the object to change state
Action
• output of a signal or an operation call
UML 2.0 State Machine Diagram
Event & Action
Event
stimulus which causes the object to change state
Action
output of a signal or an operation call
Scott Uk-Jin Lee CSE4006 Software Engineering
State Machine Diagram
Transition
• Change state from one to another triggered by an event
• Occur only when guard condition is true
• Syntax : event(arguments)[condition]/action
UML 2.0 State Machine Diagram
Transition
Change state from one to another triggered by an event
Occur only when guard condition is true
Syntax: event(arguments)[condition]/action
Scott Uk-Jin Lee CSE4006 Software Engineering
State Machine DiagramInternal Activities
• States can react to event without transition
• putting the event, guard, and activity inside the state box
• two special activities: the entry and exit activities
• Internal activity is similar to self-transition • however, internal activities do not trigger the entry and exit activity
UML 2.0 State Machine Diagram
Internal Activities
States can react to events without transition
putting the event, guard, and activity inside the state boxtwo special activities: the entry and exit activities
Internal activity is similar to self-transition
however, internal activities do not trigger the entry and exitactivities
Scott Uk-Jin Lee CSE4006 Software Engineering
State Machine DiagramActivity States
• Regular activity • instantaneous behavior
• cannot be interrupted
• Do-activities • takes finite time
• can be interrupted
• A normal state is quiet and waiting for the next event before it does something
• Activity state is doing some on-going work
UML 2.0 State Machine Diagram
Activity States
Regular activitiesinstantaneous behaviorcannot be interrupted
Do-activitiestakes finite timecan be interrupted
A normal state is quiet and waiting for the next event beforeit does something
Activity state is doing some on-going work
Scott Uk-Jin Lee CSE4006 Software Engineering
UML 2.0 State Machine Diagram
Activity States
Regular activitiesinstantaneous behaviorcannot be interrupted
Do-activitiestakes finite timecan be interrupted
A normal state is quiet and waiting for the next event beforeit does something
Activity state is doing some on-going work
Scott Uk-Jin Lee CSE4006 Software Engineering
State Machine Diagram
Superstate
• Several states share common transitions and internal activities • move the shared behavior into a superstate
• a behavior can expressed in a modular/hierachical way
UML 2.0 State Machine Diagram
Superstates
Several states share common transitions and internal activities
move the shared behavior into a superstatea behavior can be expressed in a modular/hierarchical way
Scott Uk-Jin Lee CSE4006 Software Engineering
State Machine Diagram - Example
State Machine Diagram - Example
State Machine Diagram - Example
Sequence Diagram
Sequence Diagram
• Emphasize on the sequence of communications between parts
• Show sequences of messages (“interactions”) between instances in the system
• Emphasize time ordering
UML 2.0 Sequence Diagram
Sequence Diagrams
Emphasize on the sequence of communications between parts
Show sequences of messages (“interactions”) betweeninstances in the system
Emphasize time ordering
Scott Uk-Jin Lee CSE4006 Software Engineering
Sequence Diagram
Lifelines
• Individual participant in the interaction over period time • Subsystem/ object/ class
• Actor
• External system roles in the interaction
UML 2.0 Sequence Diagram
Lifelines
Individual participant in the interaction over period timeSubsystem/ object/ classActorExternal system rolesin the interaction
Scott Uk-Jin Lee CSE4006 Software Engineering
Sequence Diagram
Messages
• Defines an expression of interaction fragements
• May have parameters that convey values
UML 2.0 Sequence Diagram
Messages
Defines an expression of interaction fragments
May have parameters that convey values
Scott Uk-Jin Lee CSE4006 Software Engineering
Sequence DiagramCombined Fragment Frame
• One-way communication between two objects
• Interaction operator define how contents describe behavior • Alt : each section is one alternative (e.g., alt [a>0])
• Ref : reference to another Use Case
• Loop : specifies a repeated sequence of behavior (e.g., ‘loop[1,5]’, ‘loop[6]’)
UML 2.0 Sequence Diagram
Combined Fragment Frame
One-way communication between two objects
Interaction operators define how contents describe behaviorAlt: each section is one alternative (e.g., alt [a>0])Ref: reference to another Use CaseLoop: specifies a repeated sequence of behavior(e.g., ‘loop [1,5]’, ‘loop [6]’)
Scott Uk-Jin Lee CSE4006 Software Engineering
Sequence Diagram
Referencing
• Reuse already existing sequence diagrams • Avoid unnecessary duplication
UML 2.0 Sequence Diagram
Referencing
Reuse already existing sequence diagrams
Avoid unnecessary duplication
Scott Uk-Jin Lee CSE4006 Software Engineering
Sequence Diagram - Example
Sequence Diagram - Example
Sequence Diagram - Example
2. Draw a state machine diagram for a digital watch • There are 3 modes : normal, stop watch, alarm
3. Draw a sequence diagram for borrowing books in the library
• The system needs to authorize
1. Draw a class diagram for POS system of book store • Stock management, Payment management At least 4 classes
Exercise
AdditionalClass diagram tutorials • http://www.tutorialspoint.com/uml/uml_class_diagram.htm
• http://www.sewo.biz/UML2/UML2ClassDiagrams1.php
• https://www.youtube.com/watch?v=3cmzqZzwNDM
• http://www.agilemodeling.com/artifacts/classDiagram.htm
State machine diagram tutorials • http://www.agilemodeling.com/artifacts/stateMachineDiagram.htm
• http://www.uml-diagrams.org/bank-atm-uml-state-machine-diagram-example.html
• http://www.tutorialspoint.com/uml/uml_statechart_diagram.htm
• https://www.youtube.com/watch?v=_6TFVzBW7oo
Additional
Squence diagram tutorials • https://youtu.be/cxG-qWthxt4
• http://www.agilemodeling.com/artifacts/sequenceDiagram.htm
• http://www.uml-diagrams.org/sequence-diagrams-examples.html
• http://www.tutorialspoint.com/uml/uml_interaction_diagram.htm