Skip to Content.
Sympa Menu

gang-of-4-patterns - RE : [gang-of-4-patterns] query on composite pattern

gang-of-4-patterns AT lists.cs.illinois.edu

Subject: Design Patterns discussion

List archive

RE : [gang-of-4-patterns] query on composite pattern


Chronological Thread 
  • From: "Mikal Ziane" <Mikal.Ziane AT lip6.fr>
  • To: <rajesh AT cs.iitm.ernet.in>, <gang-of-4-patterns AT cs.uiuc.edu>
  • Subject: RE : [gang-of-4-patterns] query on composite pattern
  • Date: Thu, 20 Nov 2003 18:57:56 +0100
  • Importance: Normal
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns/>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>

1) yes Rajesh, composite aims at treating composites and individual
objects (leaves) uniformly.
However there are several interpretations of what "treating uniformly"
means :
http://home.earthlink.net/~huston2/dp/composite.html
Two typical interpretations :
- All elements are seen as composites. This simplifies client code but
someone has to check for consistency. Methods specific to composites
may for example raise exceptions in leaves but then some code should
anyway prevent these exceptions to occur (since final users are probably
be allowed to make mistakes when assembling elements).
- All elements have the methods (or some methods) of leaves.

2) a typical naïve design is one in which you do have an interface to
hide leaves, say Leave but composite classes are not subtypes of Leave.
This makes client code more complex because a collection of leaves
cannot hold composite objects and applying some methods on Leaves and
composites is cumbersome.

> -----Message d'origine-----
> De :
> gang-of-4-patterns-admin AT cs.uiuc.edu
> [mailto:gang-of-4-patterns-
> admin AT cs.uiuc.edu]
> De la part de
> rajesh AT cs.iitm.ernet.in
> Envoyé : jeudi 20 novembre 2003 06:06
> À :
> gang-of-4-patterns AT cs.uiuc.edu
> Objet : [gang-of-4-patterns] query on composite pattern
>
> Hello,
>
> 1) What is the exact problem the composite pattern is addressing?
> Can I formulate it(problem) like , how do we represent part-whole
> hierarchies and to treat individual objects and compositions
uniformly?
> (is this the problem ?)
>
> 2) Assume that we don't have composite pattern.How do we achieve the
> solution for the problem that the composite pattern is addressing.In
other
> words, What is the bad smell for composite design pattern in the code
that
> doesn't have any pattern based solution? or What is the naive solution
for
> the problem of composite design pattern?
>
> looking forward for reply.
>
> regards
> rajesh
>
> --
> ===================================================================
>
>
> "Genius is one percent inspiration and 99 percent perspiration."
> -- Thomas Alva Edison
>
>
> ===================================================================
>
>
> _______________________________________________
> gang-of-4-patterns mailing list
> gang-of-4-patterns AT cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/gang-of-4-patterns






Archive powered by MHonArc 2.6.16.

Top of Page