Thread: Composite vs Decorator pattern?

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    Composite vs Decorator pattern?

    Hi,
    I need to create a class derived from net.sourceforge.cruisecontrol.Publisher which contains a list of objects of that same interface class and just calls the function in one of the objects in the list depending on the input.
    Ex. If it's trying to send an E-mail to people who prefer Text Only E-mails, it calls a Publisher class that sends in only Plain Text, otherwise it sends using the HTMLEmailPublisher class...

    From the UML diagrams on these pages, I believe it's a Composite pattern that I'm talking about, but someone else seems to think it's a Decorator. Any thoughts on who is right?

    Composite pattern - Wikipedia, the free encyclopedia
    Decorator pattern - Wikipedia, the free encyclopedia
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    From what I've seen, the decorator pattern is an "unstructured tree". You take an object, wrap it it another object, put that object in another. So on and so on. Almost like a russian doll. Then you call the interface method on it and it executes all of the items bubbling down to the center.

    If you only care that a certain object has certain properties and it doesn't matter the order, the decorator pattern seems the a good choice.

    With the Composite, it's more structured. You have base items and composite items. A composite can contain more than one item, while the leaf is on it's own. A tree-like pattern if you will

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rotating composite objects with OpenGL
    By elad in forum Game Programming
    Replies: 11
    Last Post: 10-19-2008, 07:04 AM
  2. Composite Classes
    By w274v in forum C++ Programming
    Replies: 2
    Last Post: 03-26-2006, 05:26 PM
  3. composite trapezoidal rule
    By Sam Robinson in forum C Programming
    Replies: 0
    Last Post: 05-19-2003, 10:01 AM
  4. Composite inheritance
    By inakappeh in forum C++ Programming
    Replies: 4
    Last Post: 03-09-2002, 01:00 AM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM