C++ UML 다이어그램 중
클래스 다이어그램에 대해 알아보자.
![](//i1.daumcdn.net/deco/contents/emoticon/things_11.gif?v=2)
이때까지 C++을 공부하면서 UML 기호를
가끔 접했었는데, 내용 이해에 크게 문제가
되지 않아서 대충 넘어갔었다. 하지만 패턴을
공부하다보니 UML 다이어그램에 대해
꼭 알아야 할 것 같아서 포스팅을 진행한다.
배경지식이나 기본적인 이론에 대해서는 생략하겠다.
UML설계 방식은 제껴두고 클래스들간의
관계에 대해서만 짚고 넘어가겠다.
![](//i1.daumcdn.net/deco/contents/emoticon/things_10.gif?v=2)
UML Class Diagram
1. 상속 (Inheritance)
![](https://t1.daumcdn.net/cfile/tistory/210D5E33587DE42718)
![](//i1.daumcdn.net/deco/contents/emoticon/things_09.gif?v=2)
02. 인터페이스 구현 (Interface Implimentation)
![](https://t1.daumcdn.net/cfile/tistory/212A5F36587DE45030)
![](//i1.daumcdn.net/deco/contents/emoticon/things_16.gif?v=2)
03. 연관 (Association)
![](https://t1.daumcdn.net/cfile/tistory/2557763C587DE4DA04)
한 클래스가 다른 클래스를 사용한다. 때문에 두 클래스 사이의
life time은 전혀 상관이 없다. 각각 독립적으로 생성되고
연결이 될 수도, 연결이 되지 않을 수도 있다.
ex)
class Car --------- class Person
class Car {
private:
Person person;
public:
setPerson(Person _p){
this.person = _p;
// setPerson 메소드를 호출해서 사용
}
}
![](//i1.daumcdn.net/deco/contents/emoticon/things_14.gif?v=2)
04. 집합 (Aggregation)
![](https://t1.daumcdn.net/cfile/tistory/262CE133587DE6C912)
Aggregation 관계로 표현되는 전체 객체의 생성 시기가
꼭 동일할 필요는 없다. 소멸시에도 Aggregatin 관계의
클래스들이 다른 객체에 의해 공유될 수도 있다.
ex)
class Car <>------------ class Engine
class Car{
private:
Engine engine;
public:
Car(Engine _e){
this.engine = _e;
// 생성자의 매개 변수로 들어온 놈이
// 꼭 Car과 같이 생성될 필요는 없으며
// 외부에서 생성된 Engine은 다른 객체에서도
// 사용되고 있을 수도 있다.
}
};
![](//i1.daumcdn.net/deco/contents/emoticon/things_35.gif?v=2)
05. 구성 (Composition)
![](https://t1.daumcdn.net/cfile/tistory/25054437587DE7F50E)
객체의 생성과 소멸 시기가 동일하다.
즉 Car 클래스 생성자 내에서 Engine 클래스를 생성한다.
ex)
class Car <<>>------------- class Engine
class Car{
private:
Engine engine;
public:
Car(...){
this.engine = new Engine( ... );
}
};
![](//i1.daumcdn.net/deco/contents/emoticon/things_34.gif?v=2)
06. 의존 (Dependency)
![](https://t1.daumcdn.net/cfile/tistory/2335ED40587DE94C2A)
객체의 생성과 소멸 시기와는 연관이 없다.
ex)
Car - - - - - - - - - > Aircon
class Car{
...
public:
void Air( Aircon con){
con.turnOn();
// Aircon 클래스를 인자로 받아 메소드를 내부적으로 호출한다.
// Aircon 의 turnOn 의 정의가 바뀌면
// Car 에 영향을 주게 되므로 의존 관계에 있다고 말한다.
}
};
![](//i1.daumcdn.net/deco/contents/emoticon/things_28.gif?v=2)
UML 다이어그램(클래스 다이어그램)에 대해
간략하게 알아보았다. 이 정도만 알고있어도
책에 나오는 UML기호는 어느정도 알아볼 수 있다.
![](//i1.daumcdn.net/deco/contents/emoticon/things_30.gif?v=2)
간단한줄로만 알았던 UML 다이어그램이
상당히 복잡하고 덩치가 큰 분야라는 것을 알았다.
다음에 기회가 된다면 좀 더 자세히 알아보는 시간을 가지겠다.