😵 ~23.11.10
0706 | 객체의 상속관계 (association has a, aggregation has a, composition has a)
unikue
2023. 7. 6. 15:01
✅ 객체의 탈부착관계
🟩 has a 상속의 종류 |
0525 | Spring (1)-DI // 스프링, DI, IoC 컨테이너, 지시서작성
[1] 스프링이란? : Spring framework - 기업형 응용 프로그램을 보조하기 위한 쉬운 프레임워크 : Transaction Management, Dependency Injection - 스프링 프레임워크의 핵심기능 : Java SE(Standard edition) 에서 JavaEE(Enter
ala-nueva.tistory.com
스프링수업에서 한 정리내용 ▼
✔ 결합관계는 모두 association ✔ 일대 다로 부품과 결합되는 Aggregation - association 의 특별한 경우 <소유객체와 각 부품은 독립적. 부품은 여기저기 다 쓰일 수 있다.> ✔ 일대 다든 일대 일이든 부품을 모두 구성한 상태로 생성되면 Composition - aggregation의 특별한 경우 <소유객체에 여러개의 부품이 결합되어 있음 + 소유객체가 생성될때 부품도 함께 생성되고 + 소유주가 사라질때 부품도 같이 사라진다> |
#️⃣ 추가설명 In both aggregation and composition object of one class "owns" object of another class. But there is a subtle difference. aggregation과 composition 👉 객체 모두 다른 클래스의 객체를 가지고있다. 하지만 미묘한 차이가 있음. In Composition the object of class that is owned by the object of it's owning class cannot live on it's own(Also called "death relationship"). It will always live as a part of it's owning object where as in Aggregation the dependent object is standalone and can exist even if the object of owning class is dead. 👉 Composition에서 종속된 클래스의 객체는 혼자 살아남을 수 없음. (죽음관계) 종속되는 객체는 항상 소유한 객체의 일부로 살아간다. 즉 소유 객체가 죽을 경우 종속객체도 죽음. So in composition if owning object is garbage collected the owned object will also be which is not the case in aggregation. 👉 소유 객체가 가비지컬렉터에게 수집되면 종속객체도 함께 수집됨 ex. Composition의 예시 ▶ 자동차에 들어가는 특정 부품이 내장되어 생산될 경우 특정 부품은 자동차에 종속되어있으며 다른곳에 쓰지 못한다. ex. Aggregation의 예시 ▶ 자동차에 들어가는 바퀴는 자동차 뿐만 아니라 바퀴가 쓰이는 여러 이동수단에 사용될 수 있다. 개별로도 쓰일 수 있으며 자동차 분야에 문제가 생기더라도 활용될 수 있다. |
#️⃣ composition has a : 구성요소로 가지고 있다. 마름모가 차있음 ◆
class phone{
private Battery battery;
public Phone(){
battery = new Battery();
}
}
Phone phone = new Phone(); //폰을 생성하면 배터리(부품)도 생성되는 has관계
#️⃣ association has a : setter를 가지고 꽂아서 사용한다. 마름모가 아예 없음
class phone{
private Battery battery;
public Phone(){
battery;
}
}
public void setBattery(Battery battery){ // 배터리를 만들어서 꽂아넣어주는 방식
this.battery = battery;
}
#️⃣ Aggregation has a : 필요한 부품을 목록으로 가지는 경우(집합관계). 마름모가 비어있음 ◇
: 배열이 들어갈 공간만 가지고 있고 객체가 생성될때마다 배열에 들어감.
백날 정리하는거보다 강의한번 더 듣는게 이해가 잘 간다 ▼