• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Composite as a single class?

 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At work, we're creating a propritary JMS-like protocol. Today we talked about whether we should put messages and addressing info in the same object, or have a message object, and a seperate "envelope" object which holds the headers/addresses, and contains a message object,
I argued that by using envelopes and messages, we can use the composite pattern, which would allow for embedding messages inside other messages. Someone else argued that you could get away with the same with just a single message class, that can contain other messages classes, along with their header/addressing info. Certainly this is true. But all implementations I've seen of the composite pattern use two classes, a composite object and a leaf, and not one class. What are the advantages and disadvantages of each implementation?

--Mark
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark -
You might take inspiration from the W3 SOAP initiative. Not the first message format to use envelopes and headers, but SOAP does make this quite explicit. Messages contain envelopes which contain headers and bodies. You might even want to use SOAP for your message format - there are some toolkits out there (IBM SOAP4J rebranded as Apache SOAP; Apache Axis). In fact, JavaRanch has just launched a new Web Services forum that might be of interest.
regards,
paul.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mark Herschberg:
At work, we're creating a propritary JMS-like protocol. Today we talked about whether we should put messages and addressing info in the same object, or have a message object, and a seperate "envelope" object which holds the headers/addresses, and contains a message object,
I argued that by using envelopes and messages, we can use the composite pattern, which would allow for embedding messages inside other messages. Someone else argued that you could get away with the same with just a single message class, that can contain other messages classes, along with their header/addressing info. Certainly this is true. But all implementations I've seen of the composite pattern use two classes, a composite object and a leaf, and not one class. What are the advantages and disadvantages of each implementation?

--Mark


I've seen the degenerate one-class case, too. What disgusts me about it (from an OOAD perspective) is that to make it work you have to insert "==null" checks all over your code to handle the case where there are no headers. I prefer to handle the difference with polymorphism rather than if statments...
Kyle

------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
reply
    Bookmark Topic Watch Topic
  • New Topic