컴포지션 개체는 부품들이 흩어져 있어 여러 번 메모리에 접근(버스 사용)해야 함 → 성능 불리
또한 메모리 할당·해제가 많을수록 성능에 불리함
결론: 확장성은 컴포지션이 좋고, 성능은 상속이 좋음
다음 코드에서 new BB()를 하면 몇 개의 메모리 블록이 할당되는가?
public class A {}public class B { private int count; private A a0 = new A(); private A a1;}public class BB extends B { private int length; private B b = new B();}// new BB();