uml class diagrams

31
UML Class Diagrams Chapter 16 Applying UML and Patterns Craig Larman

Upload: xena-henry

Post on 04-Jan-2016

50 views

Category:

Documents


0 download

DESCRIPTION

UML Class Diagrams. Chapter 16 Applying UML and Patterns Craig Larman. Objective. 자주 사용되는 UML Class Diagram 에 대한 소개 우리가 지금까지 공부해온 객체 기술을 정리해 본다 . static object modeling. officially in UML. ,. the top format is. used to distinguish the package. SuperclassFoo. name from the class name. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: UML Class Diagrams

UML Class Diagrams

Chapter 16

Applying UML and Patterns

Craig Larman

Page 2: UML Class Diagrams

2금오공과대학 컴퓨터공학부 컴퓨터공학전공

Objective

자주 사용되는 UML Class Diagram 에 대한 소개 우리가 지금까지 공부해온 객체 기술을 정리해 본다 . static object modeling

Page 3: UML Class Diagrams

3금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.1 UML 적용하기 : 클래스 다이어그램의 일반적 표기법

java .awt ::Fontor

java .awt .Font

plain : Int = 0 { readOnly }bold : Int = 1 { readOnly }name : Stringstyle : Int = 0...

getFont (name : String ) : FontgetName () : String...

«interface»Runnable

run()

- ellipsis “…” means there may be elements , but not shown- a blank compartment officially means “unknown” but as a convention will be used to mean “no members”

SubclassFoo

...

run ()...

SuperclassFooor

SuperClassFoo { abstract }

- classOrStaticAttribute : Int+ publicAttribute : String- privateAttributeassumedPrivateAttributeisInitializedAttribute : Bool = trueaCollection : VeggieBurger [ * ]attributeMayLegallyBeNull : String [0..1] finalConstantAttribute : Int = 5 { readOnly }/derivedAttribute

+ classOrStaticMethod ()+ publicMethod ()assumedPublicMethod ()- privateMethod ()# protectedMethod ()~ packageVisibleMethod ()«constructor» SuperclassFoo ( Long )methodWithParms (parm 1 : String , parm 2 : Float )methodReturnsSomething () : VeggieBurgermethodThrowsException () {exception IOException }abstractMethod ()abstractMethod 2() { abstract } // alternatefinalMethod () { leaf } // no override in subclasssynchronizedMethod () { guarded }

3 common compartments

1. classifier name

2. attributes

3. operations

interface implementation andsubclassing

Fruit

...

...

PurchaseOrder

...

...

1

association with multiplicities

dependency

officially in UML , the top format is used to distinguish the package name from the class name

unofficially , the second alternative is common

order

an interface shown with a keyword

Page 4: UML Class Diagrams

4금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.2 정의 : Design Class Diagram

Register

...

endSale()enterItem(...)makePayment(...)

Sale

timeisComplete : Boolean/total

makeLineItem(...)

Register

...

Sale

timeisComplete : Boolean/total

Captures

1

11Domain Model

conceptual perspective

Design Model

DCD; software perspective

currentSale

두 가지 관점에서 본 UML Class Diagram

Page 5: UML Class Diagrams

5금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.3 Classifier

클래스 , 인터페이스 , 유즈케이스 , 액터들을 포함하는 UML 의 많은 요소

행위적이고 구조적인 특색을 표현하는 모델링의 요소

Page 6: UML Class Diagrams

6금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.4 UML 속성을 보여주는 방법

Register

...

...

Sale

...

...

1

Register

currentSale : Sale

...

Sale

...

...

using the attribute text notation to indicate Register has a reference to one Sale instance

using the association notation to indicate Register has a reference to one Sale instance

OBSERVE: this style visually emphasizes the connection between these classes

currentSale

Register

currentSale : Sale

...

Sale

...

...

1thorough and unambiguous, but some people dislike the possible redundancy

currentSale

Page 7: UML Class Diagrams

7금오공과대학 컴퓨터공학부 컴퓨터공학전공

도메인 모델과 DCD 의 차이점

the association name, common when drawing a domain model, is often excluded (though still legal) when using class diagrams for a software perspective in a DCD

Register

id: Int

...

Sale

time: DateTime

...

1

currentSale

Register

id : Int

Sale

time : DateTime

Captures-current-sale1 1UP Domain Modelconceptual perspective

UP Design ModelDCD

software perspective

Page 8: UML Class Diagrams

8금오공과대학 컴퓨터공학부 컴퓨터공학전공

가이드 라인 : 속성 표현을 위하여 속성과 연관 중 선택한다면 ?

기본 데이터 타입을 갖는 속성은 속성으로 다른 것은 연관으로 표현

Register

id: Int

...

Sale

time: DateTime

...

1applying the guideline to show attributes as attribute text versus as association lines

Store

address: Addressphone: PhoneNumber

...

1

Register has THREE attributes:1. id2. currentSale3. location

currentSale

location

Page 9: UML Class Diagrams

9금오공과대학 컴퓨터공학부 컴퓨터공학전공

컬렉션 속성

notice that an association end can optionally also have a property string such as {ordered, List}

Sale

time: DateTime

...

SalesLineItem

...

...

1..*lineItems

{ordered, List}

Sale

time: DateTimelineItems : SalesLineItem [1..*] orlineItems : SalesLineItem [1..*] {ordered}

...

SalesLineItem

...

...

Two ways to show a collection attribute

Page 10: UML Class Diagrams

10금오공과대학 컴퓨터공학부 컴퓨터공학전공

15.6 노트 기호 : 메모 , 주석 , 제약사항 , 메소드 몸체

Register

...

endSale()enterItem(id, qty)makeNewSale()makePayment(cashTendered)

«method»// pseudo-code or a specific language is OKpublic void enterItem( id, qty ){ ProductDescription desc = catalog.getProductDescription(id); sale.makeLineItem(desc, qty);}

Page 11: UML Class Diagrams

11금오공과대학 컴퓨터공학부 컴퓨터공학전공

오퍼레이션의 형식

자바와 같은 언어도 사용가능

클래스 다이어그램에서 메소드 표현

16.6 오퍼레이션과 메소드

Register

...

endSale()enterItem(id, qty)makeNewSale()makePayment(cashTendered)

«method»// pseudo-code or a specific language is OKpublic void enterItem( id, qty ){ ProductDescription desc = catalog.getProductDescription(id); sale.makeLineItem(desc, qty);}

Page 12: UML Class Diagrams

12금오공과대학 컴퓨터공학부 컴퓨터공학전공

기타 이슈

생성자 create 를 사용

– 구현 시 각 언어에 맞게 변환하여 사용할 것 <<constructor>> 의 스테레오 타입을 사용할 수도 있다 .

접근자 getPrice(), setPrice()

주로 생략

– 중요한 정보를 포함하지 않음

– Noise 가 될 수 있음

Page 13: UML Class Diagrams

13금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.7 키워드

Page 14: UML Class Diagrams

14금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.7 스테레오 타입 , 프로파일 , 태그

스테레오 타입 <<destroy>> : 이미 정의된 키워드 <<authorship>> : 사용자 정의

Page 15: UML Class Diagrams

프로파일

UML Profile: UML Profile 은 UML 의 기본 빌딩 블록들을 특별한 목적에 맞도록 UML 의 stereotype 과 tagged value 두 가지 자체 확장 메커니즘을 사용해서 확장한 것이다 . 특정한 모델링 개념의 정의 UML 의 확장 기능

stereo type, tags, constraints 예 . 프로젝트 관리를 위한 UML 프로파일 , 데이터 모델링을 위한

UML 프로파일

15금오공과대학 컴퓨터공학부 컴퓨터공학전공

«stereotype»Authorship

author: Stringstatus : String

UML extension relationship to a basic UML metamodel term –Element

«authorship»author = “craig”status = “tested”

«metaclass»Element

...

«authorship»Square

...

using the stereotype

a tool will probably allow a popup to fill in the tag values, once an element has been stereotyped with «authorship»

declaring the stereotype

Page 16: UML Class Diagrams

16금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.8 UML 프로퍼티

a property is "a named value denoting a characteristic of an element.

A property has semantic impact

Some properties are predefined and Others can be user-defined.

Properties of elements may be presented in many ways {name1=value1, name2=value2}

ex. {abstract, visibility=public}. where {abstract=true}.

Page 17: UML Class Diagrams

Generalization

In a domain model it implies the superclass is a superset and the

subclass is a subset.

in a DCD software-perspective class diagram it implies OOPL inheritance from the superclass to

subclass.

17금오공과대학 컴퓨터공학부 컴퓨터공학전공

Page 18: UML Class Diagrams

abstract classes and operations can be shown either with an {abstract} tag

or by italicizing the name

왜 , abstract class 가 필요한가 ?

final classes are shown with the {leaf} tag.

18금오공과대학 컴퓨터공학부 컴퓨터공학전공

Page 19: UML Class Diagrams

19금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.11 의존 관계

공급자의 변경이 클라이언트에게도 영향을 주는 관계 클라이언트 공급자 결합도의 또 다른 형태 예

공급자 타입의 속성을 갖는 형태 공급자에게 메시지를 보내는 형태 공급자 클래스 타입의 매개 변수를 받는 형태 공급자가 슈퍼클래스이거나 인터페이스인 형태

이미 의존관계가 표시되는 경우 사용하지 말 것 예 . 상속 관계 , 인터페이스의 구현 , 연관

Page 20: UML Class Diagrams

20금오공과대학 컴퓨터공학부 컴퓨터공학전공

가이드 라인 객체들간의 전역 변수 , 매개변수 , 지역 변수 , 정적

메소드의 의존 관계 표현

예 .

SalesLineItem

...

...

ProductDescription

...

...

1..*lineItems

Sale

...

updatePriceFor( ProductDescription )...

the Sale has parameter visibility to a ProductDescription, and thus some kind of dependency

Page 21: UML Class Diagrams

21금오공과대학 컴퓨터공학부 컴퓨터공학전공

의존관계 레이블

System

...

runFinalization()...

Foo

...

doX()...

the doX method invokes the runFinalization static method, and thus has a dependency on the System class

Page 22: UML Class Diagrams

22금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.12 인터페이스

«interface»Timer

getTime()

Clock1

...

getTime()... lollipop notation indicates Clock3 implements

and provides the Timer interface to clients

Timer is a provided interface

Timer

Clock3

...

getTime()...

Window2

Window3

dependency line notation

Window2 has a dependency on the Timer interface when it collaborates with a Clock2 object

socket line notation

Window3 has a dependency on the Timer interface when it collaborates with a Clock3 object

Window1 Timer

socket line notation

Window1 uses the Timer interface

it has a required interface

Clock2

...

getTime()...

Clock1 implements and provides the Timer interface

Timer

Page 23: UML Class Diagrams

23금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.13 어그리게이션과 컴포지션

Aggregation 느슨한 전체와 부분 관계 연관과 별 차이가 없다 . 가능하면 사용하지 말 것

Composition 강한 전체와 부분 관계

Composition 관계는 1) 특정 시간에 부분은 전체에 포함2) 부분은 항상 하나의 전체에 포함3) 전체는 부분의 생성과 삭제를 책임 진다 . 즉 전체가 없어지면 부분도 자동으로 삭제되어야 한다 .

Finger0..7

Hand

composition

1

Square40

Board1

SalesLineItem1..*

Sale1

composition means -a part instance (Square) can only be part of one composite (Board) at a time

-the composite has sole responsibility for management of its parts, especially creation and deletion

Page 24: UML Class Diagrams

24금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.14 제약 사항

Stack

size : Integer { size >= 0 }

push( element )pop() : Object

three ways to show UML constraints

{ post condition: new size = old size + 1 }

{ post condition: new size = old size – 1 }

Page 25: UML Class Diagrams

25금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.15 한정적 연관관계

ProductCatalog

ProductDescription

itemID Contains

ProductCatalog

ProductDescription

Contains

1..*

multiplicity reduced to 1

(a)

(b)

qualifier

1

11

Page 26: UML Class Diagrams

26금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.16 연관 클래스

salarystartDate

Employment

EmploysCompany Person**

a person may have employment with several companies

Page 27: UML Class Diagrams

27금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.17 Singleton 클래스

1ServicesFactory

instance : ServicesFactory

accountingAdapter : IAccountingAdapterinventoryAdapter : IInventoryAdaptertaxCalculatorAdapter : ITaxCalculatorAdapter

getInstance() : ServicesFactory

getAccountingAdapter() : IAccountingAdaptergetInventoryAdapter() : IInventoryAdaptergetTaxCalculatorAdapter() : ITaxCalculatorAdapter...

UML notation: in a class box, an underlined attribute or method indicates a static (class level) member, rather than an instance member

UML notation: this '1' can optionally be used to indicate that only one instance will be created (a singleton)

Page 28: UML Class Diagrams

28금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.18 템플릿 클래스와 인터페이스

«interface»List

clear()...

Kparameterized or template interfaces and classes

K is a template parameter

anonymous class with template binding complete

Board

squares : List< K Square> orsquares : List< Square>...

ArrayList< T Square>

clear()...

the attribute type may be expressed in official UML, with the template binding syntax requiring an arrow

orin another language, such as Java

ArrayList

elements : T[*]...

clear()...

T

for example, the elements attribute is an array of type T, parameterized and bound before actual use.

there is a chance the UML 2 “arrow” symbol will eventually be replaced with something else e.g., ‘=’

Page 29: UML Class Diagrams

29금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.19 사용자 정의 구획

DataAccessObject

id : Int...

doX()...

exceptions thrownDatabaseExceptionIOException

responsibilitiesserialize and write objectsread and deserialize objects...

Page 30: UML Class Diagrams

30금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.20 액티브 클래스

자신의 쓰레드를 실행하고 제어

«interface»Runnable

run()

Clock

...

run()...

active class

Page 31: UML Class Diagrams

31금오공과대학 컴퓨터공학부 컴퓨터공학전공

16.21 Interaction Diagram and Class Diagram

Interaction Diagram 을 그리고 나서 Class Diagram 을 그린다 .

: Register : Sale

makePayment(cashTendered)

makePayment(cashTendered)

Register

...

makePayment(…)...

Sale

...

makePayment(…)...

1

currentSale

messages in interaction diagrams indicate operations in the class diagrams classes

identified in the interaction diagrams are declared in the class diagrams