1. Aggregation(따로 죽자)

Class Club() {

          Person[] person = null;

          Int i = 0;

          Public setRegisterPerson (Person[] p[]) {

                       person = System.ArrayCopy(p[]);

          }

}

- 일부분이 되는관계

(Aggregation is the part-of relationship.)

- 부분과 전체관계

- 하나의 객체가 다른 객체들의 조합에 의해 만들어진 것

- 공유가능

- ex)      차 – 엔진,

             컴퓨터 – 모니터, CD-ROM, 키보드

             클럽 – 사람

             식사 – 디저트, 샐러드, 수프

 

2. Composition(같이 죽자)

Class Polygon() {

          Point[] point = null;

          Public Polygon() {

                       point =  new Point[100];

          }

}

- 공유되지 않음 전체(Polygon)이 삭제될 때, 부분(Point)도 같이 삭제됨

(Thre no sharing rule is the key to composition.)

- ex)      나무 – 잎사귀

             셔츠 – 소매, 단추, 단추구멍

             커피테이블 – 몸체, 다리(4)

 

핵심은 Life Time이네요~(같이 죽자, 따로 죽자)

A Class가 B Class를 포함하고 있다면 Aggreation은
A Class가 Terminate된다고 해서 B Class가 Terminate되지 않는다.
그러나,
Composition의 경우 A Class가 Terminate되면 B Class도 Terminate된다.
Aggregation의 Life Time에 있어 독립적이지만 Composition은 종속적이다.

참고 URL : http://www.ibm.com/developerworks/kr/library/sep04/bell/




Posted by 파이팅야
,