jeudi 7 février 2019

Design pattern for creating a pojo elegantly

I have to make a layer that pulls in data from three different sources based on some setting as we are trying to migrate to new systems and we still want to maintain legacy flow till we switch.

Lets say that we need to get a consolidate POJO which contains secondary heavy POJOs.

class X { 
   Y1 obj1;
   Y2 obj2;
   Y2 obj3;
...
}

I have made a layer which can call the either of the downstream service and brings in the data. How i would like to have is that each of Y1 and Y2 and Y3 have their own populators and they could be built from the different types of POJO from different services that this layer is calling. Is there an elegant way to do this so that later on, I only have to do code addition. Also, I would like to adhere as much as possible to SOLID principles.

One way i thought of is to have a strategy pattern for each type of Y's and we select the strategy to transform based on the service and its pojo passed.

But this leads to class boom for each new complex Y inside X, I will have to write multiple strategies which is basically a lot of classes for a simple thing.

Aucun commentaire:

Enregistrer un commentaire