vendredi 7 avril 2017

Design pattern for generating multiple documents based on data sources

I'm doing a software that can generate multiple types of documents.

Let's say it can generate shipment documents for US containing the following attributes on a XML:

  • recipient full name (provided by CustomerService)
  • recipient address (provided by AddressService)
  • product (provided by ProductService)

If the product type is ProductType.CAR, the document should also have the Car model (provided by CarService given the product id previously fetched by the ProductService).

I also want to be able to generate another document that uses the same services, but present information on different ways (for instance, only last name instead of full name).

My goal is to fetch these information as lazy as possible (ie, I don't want to begin generating the document by calling all the possible sources of information of the document - mostly because that would require me to set a hierarchy for the calls since 1 information may depend on another - in the example above, I need to provide the product ID fetched from ProductService to the CarService if the product happens to be a car).

Does that looks like some design pattern?

I'm in doubt mostly between Bridge and Builder... but I couldn't make it work with any of them so far. I always end up with some business logic inside my DocumentWriter; or with some calls that just NoOp.

Aucun commentaire:

Enregistrer un commentaire