Inheritance vs Composition
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   JAMES_WEST
Posted On:   Thursday, January 29, 2004 12:56 AM

Hi guys,

I got another conceptual question right here. I need help on this one too. Which is a more static relationship -Inheritance or Composition?

I feel its inheritance because it models an "is a" relationship and its executed at compile time.

Correct me if I am wrong, Please I need your inputs and comments on this one.

Re: Inheritance vs Composition

Posted By:   Christopher_Koenigsberg  
Posted On:   Thursday, January 29, 2004 07:42 AM

I'd say that composition is inherently much more "static" than composition, in the way you seem to be using the terms.


Composition can just be "member fields"; e.g. "A is composed of B and C" can be implemented by class A having member fields of type B and C (types known statically at compile time).


But inheritance is used in polymorphism, and you already decided earlier that polymorphism is "dynamic", according to your use of the term.


e.g. with polymorphism, you pass around parent type references, which can dynamically refer to objects of various different subtypes; the actual subtype, and consequently the actual overriden method call, can only be determined at runtime.

About | Sitemap | Contact