@HowTechStuffWorks - I haven't heard of a recommendation to use
composition over inheritance. In my opinion, it is simply based on the
problem space. If you have related entities that have commonality that
you wish to abstract, you use inheritance. Composition is preferred
when you have dependent entities where the existence/meaningfulness of
a dependent entity exists only in the context of it's containing
entity.

@pacific - I would tend to disagree with your reason. Composition
structure also is determined at compile time itself. For example,
class A contains a reference to an object of class B. Also, "base
class" means you are using inheritance so when you say "composition
can
be used to change the objects during runtime(by having a base class
pointer we can change the objects runtime)" it is not entirely
accurate.

On Jun 26, 1:39 am, "pacific :-)" <pacific4...@gmail.com> wrote:
> The problem with inheritence is that it is compile time(i.e a class A
> inheriting from class B cannot be modified again)  whereas composition can
> be used to change the objects during runtime(by having a base class pointer
> we can change the objects runtime).
>
> Correct me if i'm wrong.
>
> On Sun, Jun 26, 2011 at 7:13 AM, HowTechStuffWorks <
>
>
>
> howtechstuffwo...@gmail.com> wrote:
> > Why Composition is said to be good ahead of inheritance. I am just
> > learning C++ and it was said inheritance can be handled only by expert
> > programmers, but I dont see anything like that. Can some one give me
> > an example. Thanks in advance.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> regards,
> chinna.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to