*Benefits*

Composition over inheritance can simplify the initial design of Business
Domain<http://en.wikipedia.org/w/index.php?title=Business_Domain&action=edit&redlink=1>
classes
and provide a more stable business domain in the long term. Its advantage
over inheritance is a more thorough isolation of interests than can be
described by a hierarchy of descendant classes. Additionally, inheritance
models are often contrived during the definition of business domain classes
in order to make sense of the information in the problem domain and do not
necessarily reflect the true relationship of various system objects.

Initial design is simplified by identifying system object behaviors in
separate interfaces instead of creating a hierarchical relationship to
distribute behaviors among business domain classes via inheritance. This
approach more easily accommodates future requirements changes that would
otherwise require a complete restructuring of business domain classes in the
inheritance model. Additionally, it avoids problems often associated with
relatively minor changes to an inheritance-based model that includes several
generations of classes.


Source : 
Composition_over_inheritance<http://en.wikipedia.org/wiki/Composition_over_inheritance>

On Mon, Jun 27, 2011 at 5:33 AM, Sanket <[email protected]> wrote:

> @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 :-)" <[email protected]> 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 <
> >
> >
> >
> > [email protected]> 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 [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to