eece 310: software engineering - ubccourses.ece.ubc.ca/417/public/uml-presentation.pdf · eece 310:...

54
T H E U N I V E R S I T Y O F B R I T I S H C O L U M B I A 1 EECE 310: Software Engineering A Brief Introduction to the UML adapted form Philippe Kruchten’s slides

Upload: duongdien

Post on 01-May-2018

223 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

T H E U N I V E R S I T Y O F B R I T I S H C O L U M B I A

1

EECE 310: Software Engineering

A Brief Introduction to the UML

adapted form Philippe Kruchten’s slides

Page 2: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Outline

  Purpose & genesis   Reminder on objects and

classes   UML elements   Key UML Diagrams   From Notation to Code   UML Tools   UML References & resources

2

Page 3: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

What is a model?

  A miniature representation of something.

  A semantically closed abstraction of a system under study.

  A representation of a system that allows for investigation of the properties of the system.

3

Page 4: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

What is UML?

  Notation •  Electronics analogy •  Map analogy

  Syntax and semantics •  Casual notation and formal notation

  Usage: •  Illustration •  Forward engineering: Model ⇒ Code •  Round-trip engineering: Model ⇔ Code

4

Page 5: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

What UML is not

  Not a method in itself •  A notation designed to support various methods

for requirement analysis and software design •  E.g., (IBM) Rational Unified Process (RUP)

5

Page 6: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

A Brief History of UML

  Language ‘wars’ (1985-95): •  OOPSLA conferences as the main

battlefield   Contenders

•  OMT (JimRumbaugh) •  Booch method and notation (Grady

Booch) •  OOSE (Ivar Jacobson) •  OML (Brian Henderson-Sellers) •  And many others.

  Rational Software and the “three amigos”   Object Management Group (OMG)   ISO/IEC 19501:2005 Information

Technology Standard— Open Distributed Processing — Unified Modeling Language (UML)

6

Page 7: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Two types of UML diagrams

7

Models

Dynamic Diagrams (Behavior and Interaction

Static Diagrams

Page 8: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Key UML diagrams

  Class diagram   Sequence diagram

  Object diagram   State diagram or Statechart   Activity diagram   Deployment diagram   Use-case diagram   Collaboration diagram

8

In decreasing order ���of usefulness for���the average developer

Page 9: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Visual modeling of a software system

9

Actor A Use Case 1 Use Case 2

Actor B

user : Clerk

mainWnd : MainWnd

fileMgr : FileMgr

repository : Repository document : Document

gFile : GrpFile

9: sortByName ( )

L 1: Doc view request ( ) 2: fetchDoc( )

5: readDoc ( ) 7: readFile ( ) 3: create ( )

6: fillDocument ( )

4: create ( ) 8: fillFile ( )

Window95 ¹®¼-°ü¸® Ŭ¶óÀ̾ðÆ®.EXE

Windows NT

¹®¼-°ü¸® ¿£Áø.EXE Windows

NT

Windows95

Solaris ÀÀ¿ë¼-¹ö.EXE Alpha

UNIX IBM

Mainframe µ¥ÀÌŸº£À̽º¼-¹ö

Windows95 ¹®¼-°ü¸® ¾ÖÇø´ Document

FileManager

GraphicFile File

Repository DocumentList

FileList

user mainWnd fileMgr : FileMgr repository document :

Document gFile 1: Doc view request ( )

2: fetchDoc( ) 3: create ( )

4: create ( ) 5: readDoc ( )

6: fillDocument ( ) 7: readFile ( )

8: fillFile ( ) 9: sortByName ( )

ƯÁ¤¹®¼-¿¡ ´ëÇÑ º¸±â¸¦ »ç¿ëÀÚ°¡ ¿äûÇÑ´Ù.

È-ÀÏ°ü¸®ÀÚ´Â Àоî¿Â ¹®¼-ÀÇ Á¤º¸¸¦ ÇØ´ç ¹®¼- °´Ã¼¿¡ ¼³Á¤À» ¿äûÇÑ´Ù.

È-¸é °´Ã¼´Â ÀоîµéÀÎ °´Ã¼µé¿¡ ´ëÇØ À̸§º°·Î Á¤·ÄÀ» ½ÃÄÑ È-¸é¿¡ º¸¿©ÁØ´Ù. Forward and

Reverse Engineering

Use Case 3

Use-Case Diagram Class Diagram

Collaboration Diagram

Sequence Diagram

Component Diagram

State Diagram

GrpFile read( ) open( ) create( ) fillFile( )

rep Repository

name : char * = 0 readDoc( ) readFile( ) (from Persistence)

FileMgr fetchDoc( ) sortByName( )

DocumentList add( ) delete( ) Document

name : int docid : int numField : int get( ) open( ) close( ) read( ) sortFileList( ) create( ) fillDocument( ) fList

1 FileList

add( ) delete( )

1

File read( )

read() fill the code..

Deployment Diagram

Page 10: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Three views over the system

  Functional requirements view •  Emphasizes the functional requirements of the system from

the user's point of view. •  Includes use case diagrams.

  Static structural view •  Emphasizes the static structure of the system using

objects, attributes, operations, and relationships. •  Includes class diagrams and collaboration diagrams

  Dynamic behavior view •  Emphasizes the dynamic behavior of the system by

showing collaborations among objects and changes to the internal states of objects.

•  Includes sequence diagrams, activity diagrams and state machine diagrams.

10

Page 11: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Elements of UML Diagrams

  Model elements   Connectors   Adornments   Annotations

11

Page 12: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Reminder: Class

  A description of a set of objects that share the same attributes, operations, methods, relationships, and semantics.

  A class may use a set of interfaces to specify collections of operations it provides to its environment

12

Page 13: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Reminder: Object

  An entity with a well-defined boundary and identity that encapsulates state and behavior . •  State is represented by attributes and

relationships; •  Behavior is represented by operations, methods,

and state machines.   An object is an instance of a class.

13

Page 14: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Modeling elements: class, interface

14

Page 15: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Types of relationship in class diagrams

  Class level: •  Dependency:

•  x depends on y (for implementation, for example) •  A dependency exists between two defined elements if

a change to the definition of one would result in a change to the other.

•  Generalization (& specialization): •  x is a kind of y (taxonomy, subclassing)

  Instance level •  Association:

•  x is a part of y 15

Page 16: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Class Level: Dependency and generalization

16

Page 17: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Instance-Level Relationships

Link   The basic relationship among objects.

•  Represented as a line connecting two or more object boxes.

•  Shown on an object diagram or class diagram. •  A link is an instance of an association.

17

Page 18: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Association

  A relationship that models a bi(or multi)-directional semantic connection among instances.

  An association represents a family of links

18

Page 19: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Multiplicity

  How many object can be associated   1 = exactly one   0 .. 1 = optional (zero or one)   1 .. N = at least one   * = 0 .. N = any number   N

•  For example 4, for 4 wheels in car   m .. n

19

Page 20: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Association example

20

Page 21: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Two Special Associations

  Aggregation = grouping (e.g., “by reference”)

  Composition = is made of (e.g., “by value”)

21

Page 22: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Composition versus Aggregation

22

Course Instructor

Car Carburetor

?

?

Page 23: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Composition versus Aggregation

23

Course Instructor

Car Carburetor Composition

Aggregation

Page 24: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Composition versus Aggregation

  Assume A associated with B

  If I destroy an object A, is the associated B also destroyed? •  Yes? you probably have a composition

  If an object A1 is associated with object B1, can the same object B1 be also associated with another object A2 •  Yes? you probably have an aggregation

24

Page 25: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Composition vs. Aggregation

  The whole of a composition must have a multiplicity of 0..1 or 1, indicating that a part must be for only one whole. •  The whole of an aggregation may have any multiplicity.

  Example: •  represent real-world whole-part relationships,

•  e.g., an engine is part of a car, •  the composition relationship is most appropriate.

•  represent database relationship, •  e.g., car model engine ENG01 is part of a car model

CM01, •  an aggregation relationship is best, (as the engine,

ENG01 may be also part of a different car model) 25

Page 26: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Packages

26

Page 27: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Other major modeling elements

27

Page 28: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Collaborations and Use cases

28

Page 29: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Sequences

29

Page 30: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

States

30

Page 31: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Notes

31

Page 32: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Class Diagram

32

Page 33: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Class Diagram (2)

33

Page 34: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Class Diagram (3)

34

Names Basic

Elements

Process Structure

Process Components Guidance

Process Lifecycle

Page 35: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

More class diagrams

35

Airport

Flight

Passenger

Airline

*

* *

*

$minAge: Integer age: Integer needsAssistance: Boolean

departTime: Time /arrivalTime: Time duration : Interval maxNrPass: Integer

origin

desti- nation

name: String

name: String

{ordered}

arriving Flights

departing Flights

flights

passengers

book(f : Flight)

airline

Page 36: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Class diagram with operations

36

Connection id : int state : ConnState duration : int disconnect(l : Line) : void addLine(l : Line) : void

Line number : int state : LineState incomingCall(c : Connection) : void hungUp(p : Phone) : void pickedUp(p : Phone) : void addPhone(p : Phone) : void

2..* 0..1 2..* 0..1

Phone state : PhoneState name : string selectLine(num : int) : void pickup() : void hangup() : void ring() : void dial(num : int) : void addLine(l : Line) : void

1 1..* 1 onConnection 1..*

1 0..*

selected 1

0..*

1..* 0..* 1..* 0..* linkedLines

Switch name : string getPhone(name : string) : Phone getLine(number : string) : Line addLine(num : String) : void addPhone(p : Phone) : void linkLinePhone(name : string, num : int) : void newCall(l1 : Line, l2 : Line) : void completeConn(l : Line, c : Connection) : void destroyConn(c : Connection) : void

0..*

1

0..*

1 manages

0..*

1

0..*

1 manages

0..*

1

0..*

1 manages

Simulator processCmds(in : istream)

0..*

1

0..*

1 controls

1 1 1 1

controls

Page 37: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Sequence diagram

37

Page 38: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Sequence diagram

38 Observer pattern

Page 39: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Collaboration diagram

39

Sequence diagram

Page 40: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Sequence Diagram for a Phone Call

40

Page 41: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

State diagram

41

off

on

off

on

Page 42: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Instances of a Class (Objects)

42

triangle : Polygon center : Point = (2,2)���vertices : Point* = ((0,0), (4, 0), (2,4)) borderColor : Color = black fillColor : Color = white

triangle : Polygon

triangle

: Polygon

underlined name

attribute links

Page 43: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Object Diagram

43

Page 44: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Deployment diagram

44

Page 45: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Use-case diagram

45

Page 46: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Activity Diagram

46

Page 47: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Component Diagram

47

Page 48: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

UML Extensions

48

Page 49: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Exercise

49

Page 50: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Tools to “do UML”

  Pen and pencil (and eraser) + scanner   White board and digital camera   IBM Rational Rose & Rose XDE ($$)   IBM Rational Software Architect ($$$$$)   Microsoft Visio ($)

•  use the free Pavel Hruby stencil: http://www.softwarestencils.com/uml/index.html

  Eclipse UML Plug-in (free)   Visual Paradigm (free)   Together Designer (Borland) (free)   ArgoUML (free)   …. and many more, mostly not free

50

Page 51: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

51

Page 52: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

52

Page 53: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

References

  Books: •  Martin Fowler: UML Distilled, 3rd ed., AWL •  Grady Booch: UML User’s Guide, AWL

  On-line Tutorial & Resources •  Tutorial David Braun et al. (Kennesaw St. U) at:

http://pigseye.kennesaw.edu/~dbraun/csis4650/A&D/UML_tutorial/

•  Scott Ambler’s http://www.agilemodeling.com/ •  http://www.uml.org/ •  http://www-306.ibm.com/software/rational/uml/

53

Page 54: EECE 310: Software Engineering - UBCcourses.ece.ubc.ca/417/public/uml-presentation.pdf · EECE 310: Software Engineering ... ArgoUML (free) …. and many more, ... On-line Tutorial

Deployment Diagram

54