• 검색 결과가 없습니다.

UML 인터랙션 다이어그램 표기법 (UML Interaction Diagram)

N/A
N/A
Protected

Academic year: 2022

Share "UML 인터랙션 다이어그램 표기법 (UML Interaction Diagram)"

Copied!
35
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

UML 인터랙션 다이어그램 표기법

(UML Interaction Diagram)

(2)

Objectives

• 자주 사용되는 UML 순차도와 협력도를 그릴 수 있다.

(3)

소개

• 동적 객체 모델링은 객체들이 메시지를 주고 받으면서 상호작용하는 것 을 표현

Interaction Diagram 을 사용 – 순차도(sequence diagram)과 협력도 (communication diagram)으로 구분.

• 표기법보다는 객체지향 설계의 핵심원칙은 무엇인가가 더 중요!

3

(4)

1. 순차도와 협력도

• 교류도

– 순차도 (sequence diagram)와 협력도

– 표현력은 같음

: A myB : B

doTwo doOne

doThree

: A

myB : B 1: doTwo

2: doThree doOne

public class A {

private B myB = new B();

public void doDone() {

myB.doTwo();

myB.doThree();

} //…

}

(5)

순차도 vs. 협력도

• 객체 간의 메시지 통신을 표현하며 표현력은 같다.

• 순차도 장단점

– 보기에 편하다. 많이 사용한다.

– 공간을 많이 차지

• 협력도 장단점

– 공간을 적게 차지하면서 객체간의 협력관계를 볼 수 있다.

– 순서는 1,2,… 를 따라가야 하므로 순서를 보기에는 어려움

5

(6)

예제: makePayment

: Register : Sale

makePayment(cashTendered) makePayment(cashTendered)

: Payment create(cashTendered)

• 1. makPayment 메시지가 Register 객체에 도착. 발신자는 모름.

• 2. Register 객체는 Sale 객체에 같은 메시지를 전달.

• 3. Sale 객체는 Payment 객체를 생성

public Sale {

private Payment payment;

Public void makePayment (Money cashTendered) {

payment = new Payment(cashTendered);

//…

(7)

예제: makePayment (협력도)

1: makePayment(cashTendered)

1.1: create(cashTendered)

:Register :Sale

:Payment makePayment(cashTendered)

direction of message

7

(8)

2. 초보 UML모델러는 동적 모델에 충분한 관심이 없다.

• 지침

– 클래스 다이어그램을 이용한 정적 객체 모델링에만 시간을 소비하지 말고, 인터랙션 다이어그램을 이용하여 동적 객체 모델링을 하는 데 도 시간을 할애하라.

(9)

3. UML 인터랙션 다이어그램의 일반적 표기법

• 생명선 박스를 이용한 객체 표현

9

sales : ArrayList < Sale >

: Sale s 1 : Sale

lifeline box representing an instance of an ArrayList class , parameterized ( templatized ) to hold Sale objects

lifeline box representing an unnamed instance of class Sale

lifeline box representing a named instance

sales [ i ] : Sale

lifeline box representing one instance of class Sale , selected from the sales ArrayList < Sale > collection

x : List

«metaclass»

Font

lifeline box representing the class Font , or more precisely , that Font is an instance of class Class – an instance of a metaclass

related example

List is an interface

in UML 1 . x we could not use an interface here , but in UML 2 , this ( or an abstract class ) is legal

(10)

교류도의 일반적 표기법

• 기본 메시지 표현 문법

– 중요하지 않은 부분은 생략할 수 있다.

• Initialize(cod)

• Initialize

• D = getProductDescription(id)

• D = getProductDescription(id:ItemID)

• D = getProductDescription(id:ItemID) : ProductDescription

• Singleton 객체

return = message (parameter: Type) : returnType

: Register 1

: Store

r=doA(m:Money):Int doX

the ‘ 1 ’ implies this is a

Singleton , and accessed

via the Singleton pattern

(11)

4. 순차도의 기본적인 표기법 1

• 생명선 박스와 생명선

– UML 1.x : 점선

– UML 2.x : 점선 또는 실선

• 메시지

– 생명선 사이를 연결하는 수평 화살표 (대부분 동기 메시지) – 메시지 호출 시간 순서는 위에서 아래로.

11

: Register : Sale

doA

doB doX

doC

doD

typical sychronous message shown with a filled - arrow line a found message

whose sender will not be specified

실행명세

bar indicates focus of

control

(12)

4. 순차도의 기본적인 표기법 2

• 응답 또는 반환 나타내기

– 1. 메시지 문법을 이용, return = message(params) – 2. 응답 (또는 반환) 메시지 선 (점선)을 이용

: Register : Sale

d1 = getDate

getDate doX

aDate

(13)

4. 순차도의 기본적인 표기법 3

: Register

doX

clear

13

“self” 또는 “this”로의 메시지

– 중첩된 활성화 막대 (실행 명세)를 사용

public Register {

public void doX ( ) {

clear() //…

}

private void clear() {

}

(14)

4. 순차도의 기본적인 표기법 4

• 인스턴스의 생성

– 점선 호출과 create 라는 관용적 함수

– “new” 연산자를 실행하여 생성자를 호출시켜라는 뜻

• 객체 생명선과 객체 소멸

– C++ 같이 garbage collection이 안 되는 경우 명시적으로 기술

: Sale

: Payment create ( cashTendered )

...

the «destroy» stereotyped message , with the large X and short lifeline indicates explicit object destruction

«destroy»

X

(15)

4. 순차도의 기본적인 표기법 5 - Frame

enterItem(itemID, quantity)

: B

endSale a UML loop

frame, with a boolean guard

expression description, total

makeNewSale [ more items ]

loop

: A

15

• UML 순차도에서의 프레임(frame)

– 조건문이나 반복부분에 사용

– 프레임 연산자나 레이블, 가드로 구성 – 조건은 생명선 위에 위치

– 프레임 연산자의 종류

• alt : 가드 조건에 따라 배타적으로 실행

• loop : 가드가 참일 때만 반복적으로 실행

• Opt : 가드가 참일 때만 선택적으로 실행

• Par : 병렬적으로 수행되는 부분

• Region : 임계 영역 (오직 하나의 쓰레드만 실행 가능)

(16)

4. 순차도의 기본적인 표기법 5 - Frame

calculate

: Bar

yy xx

[ color = red ] opt

: Foo

[ color = red ] calculate

: Bar

yy xx : Foo

• UML 2.x

– Option frame 사용

– Color 가 red 일 때만 수행

• UML 1.x

– 메지지 앞에 사용

– 간단할 경우 사용 가능

(17)

4. 순차도의 기본적인 표기법 5 - Frame

: A : B

calculate doX

: C

calculate [ x < 10 ]

alt

[ else ]

17

• 상호 배타적 실행

– 프레임을 점선으로 나눔

(18)

4. 순차도의 기본적인 표기법 5 - Frame

• 컬렉션에 대한 반복

st = getSubtotal

lineItems[i] : SalesLineItem t = getTotal

loop

: Sale

st = getSubtotal

lineItems [ i ] : SalesLineItem t = getTotal

[ i < lineItems . size ] loop

: Sale This lifeline box represents one

instance from a collection of many SalesLineItem objects .

lineItems [ i ] is the expression to select one element from the collection of many

SalesLineItems ; the ‘i” value refers to the same “i” in the guard in the LOOP frame

an action box may contain arbitrary language statements ( in this case , incrementing ‘i’ )

it is placed over the lifeline to which it applies i ++

(19)

4. 순차도의 기본적인 표기법 5 - Frame

calculate

: Bar xx

[ color = red ]

opt

: Foo

loop(n)

19

• 프레임의 중첩

(20)

4. 순차도의 기본적인 표기법 6 – 순차도 연관

• 인터렉션의 사용

– 다른 인터랙션을 참조

– 단순화하거나, 다른 인터렉션을 포함시키고 싶을 때 사용

interaction occurrence note it covers a set of lifelines doA

: A : B : C

doB

sd AuthenticateUser

ref AuthenticateUser authenticate ( id )

doX

doM 1

: B : C

authenticate ( id )

doM 2

ref DoFoo sd DoFoo

doX

: B : C

doY

(21)

4. 순차도의 기본적인 표기법 6 – 정적 클래스로의 메시지

• 클래스 또는 정적 메소드 호출을 위한 도식

– 보통은 객체에게 호출하지만, 클래스의 정적 메소드를 호출할 때는 클래스가 필요

– 특정 클래스는 자바에서 메타클래스인 “Class”의 인스턴스임 – .NET에서는 “Type”이 모든 클래스의 메타클래스임

21

1 : locs = getAvailableLocales

: Foo «metaclass»

Calendar doX

message to class , or a

static method call

(22)

4. 순차도의 기본적인 표기법 6 – 다형성 표기

• virtual 함수는 {abstract}로 표기

: Register

authorize doX

: Payment { abstract }

polymorphic message object in role of abstract

superclass

: DebitPayment

doA authorize

: Foo

stop at this point – don’t show any further details for this message

: CreditPayment

doX authorize

: Bar Payment { abstract }

authorize () { abstract } ...

CreditPayment authorize () ...

DebitPayment authorize () ...

Payment is an abstract superclass , with concrete subclasses that implement the polymorphic authorize operation

(23)

4. 순차도의 기본적인 표기법 7 – 비동기적 호출과 동기적 호출

• 비동기적 메시지 호출

– 응답을 기다리지 않는다. 즉 블락(block)되지 않음 – .NET 또는 java 의 쓰레드 환경에서 사용

– 실행 도중에 쓰레드를 생성하고 초기화할 수 있다. (Thread.start) – 선으로 된 화살촉

• 동기적 메시지 호출

– 보통의 함수 호출

– 결과가 올 때까지 호출한 객체는 기다림 – 속이 꽉 찬 화살촉

23

(24)

4. 순차도의 기본적인 표기법 7 – 액티브 객체

• 액티브 객체

– 객체 자신만의 쓰레드를 실행시키고 제어함 – 박스 양쪽에 바가 추가됨

• 비동기적 호출

– run 메소드

: ClockStarter

: Clock run

startClock

create a stick arrow in UML implies an asynchronous call

a filled arrow is the more common synchronous call In Java , for example , an asynchronous call may occur as follows :

// Clock implements the Runnable interface Thread t = new Thread ( new Clock () ) ; t . start () ;

the asynchronous start call always invokes the run method on the Runnable ( Clock ) object

to simplify the UML diagram , the Thread object and the start message may be avoided ( they are standard

“overhead” ) ; instead , the essential detail of the Clock

runFinalization

System : Class active

object

(25)

4. 순차도의 기본적인 표기법 7 – 액티브 객체의 java 구현

25 public class Clock implements Runnale

{

public void run() // 쓰레드의 start함수를 부르면 자동 호출되는 함수 {

while (true) // 쓰레드안에서 무한 반복 {

///

} }

Public class ClockStarter {

public void startClock() {

Thread t = new Thread(new Clock());

t.start(); // Clock 쓰레드의 run 메소드의 비동기적 호출 System.runFinalization();

}

}

(26)

5. 협력도의 기본적인 표기법 - 링크

1: makePayment(cashTendered) 2: foo

2.1: bar

: Register :Sale

link line

• 링크

– 두 객체 사이의 연결 경로로서 연관관계의 인스턴스임

– 예를 들어 Register 클래스와 Sale 클래스의 연관이 있다면 Register 객체와 Sale 객체 사이에 링크가 존재한다.

– 링크 하나에는 여러 종류의 메시지가 흘러갈 수 있다.

(27)

5. 협력도의 기본적인 표기법 - 메시지

• 메시지

– 링크 위에 메시지 표현식과 작은 화살표로 흐름방향을 표현 – 순서번호를 사용하여 흐름 순서를 표시

– 첫 번째 메시지는 순서번호를 붙이지 않는다.

1: msg2 2: msg3 3: msg4 3.1: msg5

: Register :Sale

all messages flow on the same link msg1

27

(28)

5. 협력도의 기본적인 표기법 – “self” 및 인스턴스 생성

“self” 또는 “this”로의 메시지

– 자신으로의 루프

• 인스턴스의 생성

– <<create>> 스테레오 타입 사용 – 생성된 인스턴스 {new} 태크 사용

: Register msg1

1: clear

1 : create ( cashier )

: Register : Sale

create message , with optional initializing parameters . This will normally be interpreted as a constructor call .

«create»

1 : make ( cashier )

: Register : Sale

1 : create ( cashier )

: Register : Sale { new }

Three ways to show creation in a communication diagram

(29)

5. 협력도의 기본적인 표기법 –순서번호 매기기

• 순서번호 (sequence number) 규칙

– 1. 첫 번째 메시지는 번호를 붙이지 않는다.

– 2. 첫 번째 메시지를 호출 받은 객체가 다른 객체들에게 메시지를 보낼 때 는 1,2,3…으로 붙이고, 그 다른 객체들이 또 다시 중첩하여 메시지를 보 낼 때는 1.1, 1.2, 등으로 dot 기호를 사용한다.

msg1 : A

1: msg2 : B

: C

1.1: msg3 2.1: msg5 2: msg4

: D 2.2: msg6

first second

fourth

sixth

fifth third

29

(30)

5. 협력도의 기본적인 표기법 – 조건부 메시지 전달

• 조건 메시지

– 가드를 사용

번호 [ 조건 ] : 메시지

• 상호 배타적인 조건

1 [ color = red ] : calculate

: Foo : Bar

message1

conditional message, with test

1a [test1] : msg2

: A : B

1a.1: msg3 msg1

1b [not test1] : msg4

1b.1: msg5 : E

2: msg6 unconditional after

either msg2 or msg4 1a and 1b are mutually

exclusive conditional paths

(31)

5. 협력도의 기본적인 표기법 – 반복

1 * [ i = 1..n ]: num = nextInt : Simulator

runSimulation

: Random

iteration is indicated with a * and an optional iteration clause following the sequence number

31

• 반복 혹은 루프

– 조건 앞에 ‘*’ 를 붙임.

(32)

5. 협력도의 기본적인 표기법 – 컬렉션에 대한 반복

1 * [i = 1..n]: st = getSubtotal : Sale

t = getTotal

This lifeline box represents one instance from a collection of many SalesLineItem objects.

lineItems[i]is the expression to select one element from the collection of many

SalesLineItems; the 멼?value comes from the message clause.

lineItems[i]:

SalesLineItem

this iteration and recurrence clause indicates we are looping across each element of the lineItems collection.

1 *: st = getSubtotal : Sale

t = getTotal lineItems[i]:

SalesLineItem

Less precise, but usually good enough to imply

• 컬렉션의 객체들에 대한 똑같은 메시지 호출

(33)

5. 협력도의 기본적인 표기법 – 정적 클래스 또는 메소

• 순차도 참조하여 이해

33 1 : locs = getAvailableLocales

: Foo «metaclass»

Calendar doX

message to class , or a

static method call

(34)

5. 협력도의 기본적인 표기법 – 다형적 메시지

• 객체에 {abstract} 태그를 붙여 다형적 메시지임을 표현

: Register authorize

doX : Payment { abstract }

polymorphic message

object in role of abstract superclass

: DebitPayment authorize

: Foo

stop at this point – don’t show any further details for this message

separate diagrams for each polymorphic concrete case doA

doB : CreditPayment

authorize

: Bar doX

(35)

5. 협력도의 기본적인 표기법 – 비동기/동기 호출

비동기 – 열린 화살표, 대부분 액티브 객체로의 메시지

동기적 호출 – 채워진 화살표

3: runFinalization

:ClockStarter System : Class

startClock

:Clock

1: create 2: run

asynchronous message

active object

35

참조

관련 문서