컴포지션(Composition) - C++/C#/CS 기초
컴포지션(Composition)
📌 개념 정리
💻 예제
1
2
3
4
5
6
7
8
9
10
class Engine {
public:
void Start() { cout << "Engine start\n"; }
};
class Car {
private:
Engine engine; // 컴포지션
public:
void Drive() { engine.Start(); }
};
⚡ 주의점
- 유연성 ↑, 상속보다 결합도 낮음.
- 상속보다 권장되는 경우 많음.
🔗 관련 페이지
This post is licensed under CC BY 4.0 by the author.