lab 6: uml - software engineering lab -...

40
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.

Upload: vukhuong

Post on 02-May-2018

222 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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.

Page 2: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 3: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 4: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

CRC Cards - ExampleCRC Modeling

CRC card

Scott Uk-Jin Lee CSE4006 Software Engineering

Page 5: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

UML Diagrams

Page 6: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 7: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 8: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 9: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 10: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 11: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 12: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 13: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 14: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 15: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 16: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 17: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 18: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

Class Diagrams - Example

Page 19: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

Class Diagrams - Example

Page 20: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

Class Diagrams - Example

Page 21: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 22: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 23: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 24: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 25: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 26: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 27: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

State Machine Diagram - Example

Page 28: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

State Machine Diagram - Example

Page 29: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

State Machine Diagram - Example

Page 30: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 31: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 32: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 33: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 34: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 35: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

Sequence Diagram - Example

Page 36: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

Sequence Diagram - Example

Page 37: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

Sequence Diagram - Example

Page 38: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 39: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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

Page 40: Lab 6: UML - Software Engineering Lab - Homeselab.hanyang.ac.kr/courses/cse406/2016/labs/lab6.pdf ·  · 2016-04-14Association • Relationship ... Aggregation & Composition Aggregation

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