Skip to Content.
Sympa Menu

gang-of-4-patterns - Re: [gang-of-4-patterns] Difference between Decorator and Visitor

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

Subject: Design Patterns discussion

List archive

Re: [gang-of-4-patterns] Difference between Decorator and Visitor


Chronological Thread 
  • From: Lorenzo Bettini <bettini AT dsi.unifi.it>
  • To: rajesh AT cs.iitm.ernet.in
  • Cc: gang-of-4-patterns AT cs.uiuc.edu
  • Subject: Re: [gang-of-4-patterns] Difference between Decorator and Visitor
  • Date: Tue, 20 Jul 2004 22:57:27 +0200
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>

rajesh AT cs.iitm.ernet.in
wrote:
Dear members,

What is main difference between Decorator and Visitor pattern? I can not find any difference? Both are used to add additional responsibilities dynamically. why one is categorized into structural and other in behaviorial categories? I wonder if some body could clarify my doubt. Looking forward for reply.

well Decorator lets you create a "chain" of objects (each object is inside the other) and each object "specializes" a behavior (i.e. it performs the behavior of the included object and performs its own behavior), w.t.r. it is structural.

Visitor lets you act differently according the dynamic type of objects (a sort of manual implementation of double dispatch, see, e.g., http://www.lorenzobettini.it/software/doublecpp), and w.t.r. it is behavioral...

Hope it helps

Lorenzo

--
+-----------------------------------------------------+
| Lorenzo Bettini ICQ# lbetto, 16080134 |
| PhD in Computer Science |
| Dip. Sistemi e Informatica, Univ. di Firenze |
| Florence - Italy (GNU/Linux User # 158233) |
| Home Page : http://www.lorenzobettini.it |
| http://music.dsi.unifi.it XKlaim language |
| http://www.lorenzobettini.it/purple Cover Band |
| http://www.gnu.org/software/src-highlite |
| http://www.gnu.org/software/gengetopt |
| http://www.lorenzobettini.it/software/gengen |
| http://www.lorenzobettini.it/software/doublecpp |
+-----------------------------------------------------+





Archive powered by MHonArc 2.6.16.

Top of Page