lundi 12 avril 2021

Building a composite object from collection of entities

I am trying to find a good way of constructing an object from a collection of entities. The object I want to construct has concrete implementations and the input I have is collection of supertype. I don't want to resort to using typecasting or instanceof check. Is there a good design for achieving this? I am not sure if visitor pattern with state serves useful here.

Scenario: I want to construct a DataModel class which has properties that are concrete implementations of DataSourceEntity. E.g

public class DataModel {
   private ClientAuthInfo clientAuthInfo;
   private CustomerAuthContext customerAuthContext;
   private RiskProfile riskProfile;
  // ...
} 
public class ClientAuthInfo implements DataSourceEntity {
}

public class CustomerAuthContext implements DataSourceEntity {
}

// ...

Input: List<DataSourceEntity> Output: DataModel

In short converting List<DataSourceEntity> -> DataModel

Aucun commentaire:

Enregistrer un commentaire