lundi 25 mai 2020

Which design pattern should be used if same input comes from different data sources and final object is exactly the same

I need to create an object where input can come from different data sources and final object created is of same class type. For instance

Input source (constructor argument) can either be:

1. file path as string
2. content as string

Note: Data type for both is same which is String.

Which design patter should I use?

I am thinking of using "Simple Factory" and add the methods:

ClassA fromFilePath(String){}
ClassA fromContent(String){}

However not sure where to put the logic to load/process the content from input source to create/initialise the instance.

Please advise.

Aucun commentaire:

Enregistrer un commentaire