We have a smelly code in our project. A lot of values which used in biz logic have 2 places where they stored: we have dictionary tables (used in FK relations) in DB where we stored values e.x. MessageDirectionInfo:
0|Unknown
1|In
2|Out
and we have Enum with exactly same data: MessageDirectionEnum{Unknown=0,In=1,Out=2} And all over the code we have a lot of ‘switch’ and ‘if’ where enum used for conditional logic. But when we saving to DB – we should ‘convert’ (which actually ‘blind select’, case its selecting exact same data except result object type) Enum value to Dictionary class instance. I can understand that Enums is used to clear code logic and DB data used to reference in foreign keys, but actually i dont like this.
Is there any pattern to remove such behaviour or any way to clear some of this ‘smelly way’ ? Or maybe I’m just blind and this is the only clear way to get both benefits – DB FKs and clearer code logic with enums
Keep the table but replace the Enum with classes…? http://www.refactoring.com/catalog/replaceTypeCodeWithClass.html