October 19, 2007


Inheritance Vs. Composition vs Parameterized Types:
Inheritance - white-box-reuse. Internals of parent class visible.
Inheritance defined at compile time. Possible to modify implementation. (overriding)
Disadv - Parent class influence the physical representation.
Composition - black box reuse. No internal details visible.
Composition - defined at run time. Wont break encapsulation. Class hierarchies will remain small.
General rule of thumb - Prefer Composition over Inheritance.
Parmeterized Types - Generics , Templates

1 comment:

Pallavi said...

you became a java expert.:)
Prefer composition over inheritance?
I don't know. I some how feel both are designed for different reasons.

But, your blog is going to be a crash tutorial for java learners. :)
I am learning a lot. :D