Home > Blockchain >  Decorating a domain object from multiple data sources. Poor design?
Decorating a domain object from multiple data sources. Poor design?

Time:10-30

I have a primary data source that will return JSON data which I unmarshall to a java POJO. The secondary data source then uses information from the first Java POJO classes to retrieve additional data from another data source.

My original plan was to have a single POJO that is partially populated by data source one and then completed by data source 2.

But from a purist point this would seem wrong, but I am unsure how you should design the system.

Just for reference, there is no need for this to be done asynchronously.

CodePudding user response:

I wouldn't have a single POJO for everything. I would go with the following:

  • Specific DTO class for the data coming from data source 1;
  • Specific DTO class for the data coming from data source 2;
  • POJO class for your domain model mapped from the 2 specific DTO classes mentioned above.

With this, you clearly separate data sources and use whatever logic you need to merge them into your domain model. With this, you decouple your domain model from the data sources, making it easier to change any of the classes if needed. You could even add or remove a data source easily.

  •  Tags:  
  • java
  • Related