inblog logo
|
devleekangho
    용어정리

    컴포지션 (Composition)

    KangHo Lee's avatar
    KangHo Lee
    Nov 21, 2024
    컴포지션 (Composition)
    Contents
    주요 개념컴포지션 vs 상속

    주요 개념

    1. 컴포지션(Composition)
        • 한 클래스가 다른 클래스의 객체를 자신의 멤버 변수로 포함하는 관계를 의미합니다.
        • "has-a" 관계로 표현되며, 객체들이 협력하여 더 복잡한 기능을 구현할 수 있게 합니다.
    1. 예시
        • Controller 클래스가 Service 클래스를 멤버 변수로 포함하는 경우, Controller has an Service 이라고 표현합니다.
    1. 예시 코드
    public class Controller { private final Service service; public Controller(Service service) { this.service = service; } }

    컴포지션 vs 상속

    • 컴포지션
      • has-a 관계를 나타내며, 클래스가 다른 클래스를 포함합니다.
    • 상속(Inheritance)
      • is-a 관계를 나타내며 클래스가 다른 클래스를 확장합니다.
     
    Share article
    Contents
    주요 개념컴포지션 vs 상속

    devleekangho

    RSS·Powered by Inblog