UML 인터랙션다이어그램표기법 (UML Interaction Diagram)
Objectives 자주사용되는 UML 순차도와협력도를그릴수있다. 2
소개 동적객체모델링은객체들이메시지를주고받으면서상호작용하는것을표현 Interaction Diagram 을사용 순차도 (sequence diagram) 과협력도 (communication diagram) 으로구분. 표기법보다는객체지향설계의핵심원칙은무엇인가가더중요! 3
1. 순차도와협력도 교류도 순차도 (sequence diagram) 와협력도 표현력은같음 : A myb : B public class A { private B myb = new B(); } public void dodone() { myb.dotwo(); myb.dothree(); } // doone doone : A dotwo dothree 1: dotwo 2: dothree myb : B 4
순차도 vs. 협력도 객체간의메시지통신을표현하며표현력은같다. 순차도장단점 보기에편하다. 많이사용한다. 공간을많이차지 협력도장단점 공간을적게차지하면서객체간의협력관계를볼수있다. 순서는 1,2, 를따라가야하므로순서를보기에는어려움 5
예제 : makepayment : Register : Sale makepayment(cashtendered) makepayment(cashtendered) create(cashtendered) : Payment 1. makpayment 메시지가 Register 객체에도착. 발신자는모름. 2. Register 객체는 Sale 객체에같은메시지를전달. 3. Sale 객체는 Payment 객체를생성 public Sale { private Payment payment; Public void makepayment (Money cashtendered) { payment = new Payment(cashTendered); // } } 6
예제 : makepayment ( 협력도 ) direction of message makepayment(cashtendered) :Register 1: makepayment(cashtendered) :Sale 1.1: create(cashtendered) :Payment 7
2. 초보 UML 모델러는동적모델에충분한관심이없다. 지침 클래스다이어그램을이용한정적객체모델링에만시간을소비하지말고, 인터랙션다이어그램을이용하여동적객체모델링을하는데도시간을할애하라. 8
3. UML 인터랙션다이어그램의일반적표기법 생명선박스를이용한객체표현 lifeline box representing an unnamed instance of class Sale lifeline box representing a named instance lifeline box representing the class Font, or more precisely, that Font is an instance of class Class an instance of a metaclass : Sale s 1 : Sale «metaclass» Font lifeline box representing an instance of an ArrayList class, parameterized ( templatized ) to hold Sale objects lifeline box representing one instance of class Sale, selected from the sales ArrayList < Sale > collection 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 sales : ArrayList < Sale > sales [ i ] : Sale x : List related example 9
교류도의일반적표기법 기본메시지표현문법 return = message (parameter: Type) : returntype 중요하지않은부분은생략할수있다. Initialize(cod) Initialize D = getproductdescription(id) D = getproductdescription(id:itemid) D = getproductdescription(id:itemid) : ProductDescription Singleton 객체 dox : Register r=doa(m:money):int : Store 1 the 1 implies this is a Singleton, and accessed via the Singleton pattern 10
4. 순차도의기본적인표기법 1 생명선박스와생명선 UML 1.x : 점선 UML 2.x : 점선또는실선 메시지 생명선사이를연결하는수평화살표 ( 대부분동기메시지 ) 메시지호출시간순서는위에서아래로. : Register : Sale dox doa a found message whose sender will not be specified dob doc dod 실행명세 bar indicates focus of control typical sychronous message shown with a filled - arrow line 11
4. 순차도의기본적인표기법 2 응답또는반환나타내기 1. 메시지문법을이용, return = message(params) 2. 응답 ( 또는반환 ) 메시지선 ( 점선 ) 을이용 : Register : Sale dox d1 = getdate getdate adate 12
4. 순차도의기본적인표기법 3 self 또는 this 로의메시지 중첩된활성화막대 ( 실행명세 ) 를사용 : Register dox clear public Register { public void dox ( ) { clear() // } private void clear() { } 13
4. 순차도의기본적인표기법 4 인스턴스의생성 점선호출과 create 라는관용적함수 new 연산자를실행하여생성자를호출시켜라는뜻 객체생명선과객체소멸 C++ 같이 garbage collection 이안되는경우명시적으로기술 : Sale create ( cashtendered )... «destroy» : Payment X the «destroy» stereotyped message, with the large X and short lifeline indicates explicit object destruction 14
4. 순차도의기본적인표기법 5 - Frame UML 순차도에서의프레임 (frame) 조건문이나반복부분에사용 프레임연산자나레이블, 가드로구성 조건은생명선위에위치 프레임연산자의종류 alt : 가드조건에따라배타적으로실행 loop : 가드가참일때만반복적으로실행 Opt : 가드가참일때만선택적으로실행 Par : 병렬적으로수행되는부분 Region : 임계영역 ( 오직하나의쓰레드만실행가능 ) : A : B makenewsale a UML loop frame, with a boolean guard expression loop [ more items ] enteritem(itemid, quantity) description, total endsale 15
4. 순차도의기본적인표기법 5 - Frame UML 2.x Option frame 사용 Color 가 red 일때만수행 UML 1.x 메지지앞에사용 간단할경우사용가능 opt : Foo [ color = red ] xx calculate yy : Bar : Foo xx : Bar [ color = red ] calculate yy 16
4. 순차도의기본적인표기법 5 - Frame 상호배타적실행 프레임을점선으로나눔 : A : B : C dox alt [ x < 10 ] calculate [ else ] calculate 17
4. 순차도의기본적인표기법 5 - Frame 컬렉션에대한반복 : Sale lineitems [ i ] : SalesLineItem This lifeline box represents one instance from a collection of many t = gettotal SalesLineItem objects. loop [ i < lineitems. size ] i ++ st = getsubtotal 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 : Sale lineitems[i] : SalesLineItem t = gettotal loop st = getsubtotal 18
4. 순차도의기본적인표기법 5 - Frame 프레임의중첩 : Foo : Bar xx opt [ color = red ] loop(n) calculate 19
4. 순차도의기본적인표기법 6 순차도연관 인터렉션의사용 다른인터랙션을참조 단순화하거나, 다른인터렉션을포함시키고싶을때사용 sd AuthenticateUser : A : B : C : B : C dox doa authenticate ( id ) ref dob AuthenticateUser authenticate ( id ) dom 1 dom 2 ref DoFoo sd DoFoo : B : C interaction occurrence note it covers a set of lifelines note that the sd frame it relates to has the same lifelines : B and C dox doy doz 20
4. 순차도의기본적인표기법 6 정적클래스로의메시지 클래스또는정적메소드호출을위한도식 보통은객체에게호출하지만, 클래스의정적메소드를호출할때는클래스가필요 특정클래스는자바에서메타클래스인 Class 의인스턴스임.NET 에서는 Type 이모든클래스의메타클래스임 dox message to class, or a static method call : Foo 1 : locs = getavailablelocales «metaclass» Calendar 21
4. 순차도의기본적인표기법 6 다형성표기 virtual 함수는 {abstract} 로표기 Payment is an abstract superclass, with concrete subclasses that implement the polymorphic authorize operation Payment { abstract } authorize () { abstract }... CreditPayment authorize ()... DebitPayment authorize ()... polymorphic message object in role of abstract superclass : Register : Payment { abstract } dox authorize stop at this point don t show any further details for this message : DebitPayment : Foo : CreditPayment : Bar authorize doa authorize dox dob separate diagrams for each polymorphic concrete case 22
4. 순차도의기본적인표기법 7 비동기적호출과동기적호출 비동기적메시지호출 응답을기다리지않는다. 즉블락 (block) 되지않음.NET 또는 java 의쓰레드환경에서사용 실행도중에쓰레드를생성하고초기화할수있다. (Thread.start) 선으로된화살촉 동기적메시지호출 보통의함수호출 결과가올때까지호출한객체는기다림 속이꽉찬화살촉 23
4. 순차도의기본적인표기법 7 액티브객체 액티브객체 객체자신만의쓰레드를실행시키고제어함 박스양쪽에바가추가됨 비동기적호출 run 메소드 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 : : ClockStarter active object System : Class // Clock implements the Runnable interface Thread t = new Thread ( new Clock () ) ; t. start () ; startclock create : Clock the asynchronous start call always invokes the run method on the Runnable ( Clock ) object run 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 creation and the run message imply the asynchronous call runfinalization 24
4. 순차도의기본적인표기법 7 액티브객체의 java 구현 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(); } 25
5. 협력도의기본적인표기법 - 링크 링크 두객체사이의연결경로로서연관관계의인스턴스임 예를들어 Register 클래스와 Sale 클래스의연관이있다면 Register 객체와 Sale 객체사이에링크가존재한다. 링크하나에는여러종류의메시지가흘러갈수있다. 1: makepayment(cashtendered) 2: foo : Register :Sale 2.1: bar link line 26
5. 협력도의기본적인표기법 - 메시지 메시지 링크위에메시지표현식과작은화살표로흐름방향을표현 순서번호를사용하여흐름순서를표시 첫번째메시지는순서번호를붙이지않는다. msg1 1: msg2 2: msg3 3: msg4 : Register :Sale 3.1: msg5 all messages flow on the same link 27
5. 협력도의기본적인표기법 self 및인스턴스생성 self 또는 this 로의메시지 자신으로의루프 : Register msg1 인스턴스의생성 <<create>> 스테레오타입사용 생성된인스턴스 {new} 태크사용 1: clear Three ways to show creation in a communication diagram create message, with optional initializing parameters. This will normally be interpreted as a constructor call. 1 : create ( cashier ) : Register : Sale 1 : create ( cashier ) : Register : Sale { new } «create» 1 : make ( cashier ) : Register : Sale if an unobvious creation message name is used, the message may be stereotyped for clarity 28
5. 협력도의기본적인표기법 순서번호매기기 순서번호 (sequence number) 규칙 1. 첫번째메시지는번호를붙이지않는다. 2. 첫번째메시지를호출받은객체가다른객체들에게메시지를보낼때는 1,2,3 으로붙이고, 그다른객체들이또다시중첩하여메시지를보낼때는 1.1, 1.2, 등으로 dot 기호를사용한다. first second third msg1 : A 1: msg2 : B 1.1: msg3 2.1: msg5 2: msg4 : C fourth 2.2: msg6 fifth sixth : D 29
5. 협력도의기본적인표기법 조건부메시지전달 조건메시지 가드를사용 번호 [ 조건 ] : 메시지 message1 conditional message, with test 1 [ color = red ] : calculate : Foo : Bar 상호배타적인조건 unconditional after either msg2 or msg4 : E 1a and 1b are mutually exclusive conditional paths 2: msg6 msg1 1a [test1] : msg2 : A : B 1b [not test1] : msg4 1a.1: msg3 : D 1b.1: msg5 : C 30
5. 협력도의기본적인표기법 반복 반복혹은루프 조건앞에 * 를붙임. runsimulation : Simulator 1 * [ i = 1..n ]: num = nextint : Random iteration is indicated with a * and an optional iteration clause following the sequence number 31
5. 협력도의기본적인표기법 컬렉션에대한반복 컬렉션의객체들에대한똑같은메시지호출 t = gettotal : Sale 1 * [i = 1..n]: st = getsubtotal lineitems[i]: SalesLineItem this iteration and recurrence clause indicates we are looping across each element of the lineitems collection. 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. t = gettotal : Sale 1 *: st = getsubtotal lineitems[i]: SalesLineItem Less precise, but usually good enough to imply iteration across the collection members 32
5. 협력도의기본적인표기법 정적클래스또는메소드 순차도참조하여이해 dox message to class, or a static method call : Foo 1 : locs = getavailablelocales «metaclass» Calendar 33
5. 협력도의기본적인표기법 다형적메시지 객체에 {abstract} 태그를붙여다형적메시지임을표현 polymorphic message stop at this point don t show any further details for this message dox : Register authorize : Payment { abstract } object in role of abstract superclass authorize authorize : DebitPayment doa dob : Foo : CreditPayment dox : Bar separate diagrams for each polymorphic concrete case 34
5. 협력도의기본적인표기법 비동기 / 동기호출 비동기 열린화살표, 대부분액티브객체로의메시지 동기적호출 채워진화살표 startclock :ClockStarter 3: runfinalization System : Class 1: create 2: run asynchronous message :Clock active object 35