2

I have data available in the form of Structs and Arrays.

I need some design pattern advice, which I can use to model this situation into corresponding Coldfusion Components.

Here is the data definition

I have objects like

  • Hotel
  • Apartment
  • Bus

Each object has it's attributes and images. Images have also different types like thumbnails, gallery etc.

Attributes may be simple or complex
Simple Attributes like: name, code, id etc
And complex attributes are themselves objects which have it's own Attributes and Images.

The second part is Customers. Our customers receive these objects as XML export files. Each customer has it's own requirements. For example some want one kind of attributes and other want other attributes. Some want that one type of images should be exported and some want all image types should be exported.

  • In JAVA you use JAXB to marshal/unmarshall your objects in XML. – Arthur Portas Apr 4 '13 at 11:00
2

Typically what I would do in that situation is to have one XML definition for each of your objects such as Hotels, Apartments and Buses. Choose the simplest possible definition, it will only be known to you. Example:

<hotel id="1">
 <property1></property1>
 <image type="X"></image>
 <image type="Y"></image>
 etc.
</hotel>

The objects you would like to export will first be serialized to XML files, given your definitions.

Then, you have to associate for each customer an XSLT file that will be able to transform your private XML file to the XML format desired by the customer. Given a source XML, with XSLT you will able to generate destination XML files with whatever attributes or elements the customer wants.

Basically, here's your process for generating XML files compatible with each customer:

  1. Serialize your objects to one or more XML files
  2. Get the XSLT file associated to your customer
  3. Apply the XSL transformation to your source XML file(s) to get the destination XML file(s)

The main advantage of this technique is that you have your own XML format, no one knows about it except you, and as such, you are not entitled to any specific/proprietary customer XML format.

It's more of a technique than a design pattern, but I guarantee you it's a good one. Finally, it's been a long time since I've done some XSLT, but if you are not familiar, check the MDN reference website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.