lundi 8 février 2016

The cleanest way to avoid multiple if-statements - object creation dependent on many params

I'm looking for the cleanest way to determine value without using multiple if-statements (or switch-case).

For example, I have following mapping table: enter image description here

As you see, I need to consider 5 variables before I will be able to determine the exact value.

Using if-statements leads to embedded ifs nightmare.

I have two solutions in mind:

Very dirty - map of maps of maps of maps, etc. :

Map<String, Map<String, Map<String,...>>> myMappings;

Involving a lot of code: Factory with sub-factories leading to final value - practically this is better for readability, but still this is if-statements encapsulated in classes.

What are your ideas?

Aucun commentaire:

Enregistrer un commentaire