jeudi 15 juillet 2021

Is it possible in my case to implement a strategy pattern with different semantics of algorithms?

Hi everyone, I am new on Stack Overflow so if you like my example please vote up so I get reputation of 50 for some extra features.


Now let's start with my problem.

I have several classes that literally convert one data model to another.

Different classes use different versions of the data model.

Here is my example: Here is my example

In this example I have 3 converters (for now) and two algorithms that convert one data model to another, but they work for different versions of the data model. For example, AlgoVerOne works for an older version of the data model while AlgoVer2 works for a newer version that contains more / less information in it.

What matters is that ConverterA and ConverterB use the same version of the data model. So the conversion algorithm is exactly the same because the versions of the data model do not differ.

PROBLEM

My problem is that the semantics of some parts are different for these two classes. Let's say there is an element in a data model that has a value of 100. This value can be converted and inserted into another data model, because these classes use the same version of it. But the semantics of value 100 for ConverterA means "car" while for ConverterB means "bus".

So the algorithm needed to convert one data model to another is the same, but the value of an element within that data model is semantically different for these two classes.

I don’t want to use a completely new algorithm for both classes because it only changes 1% of the semantics of the whole data model.

Aucun commentaire:

Enregistrer un commentaire