Last post Oct 26, 2010 05:27 AM by muhammedsalimp
Oct 26, 2010 05:11 AM|mm8|LINK
Is there any design pattern or architectural design that prevent the following type of code, where I have an enum with different fileformats and I have to make a switch anywhere I want to distinguish between the different fileformats?
public enum FileFormat
FileFormat fileformat = GetFormat();
If add an item to the enum definition in this case I have to change all the code that uses switches and that kind og enum which, I guess, is a bad approach in terms on maintenance of the application?
Oct 26, 2010 05:27 AM|muhammedsalimp|LINK
I don't think there is anything wrong in the above code.
In any case, If you want to add a new file format, You will have to write code to handle that. I think that cannot be avoided.
On the other hand, Enumerations simplify coding, avoid programming errors, and improve code readability by enabling you to use meaningful symbols instead of simple numeric values. Enumerations are always preferred when developers consuming your types must
choose from a limited set of choices for a value.
Switch statements are also recommended way of conditional statements and have advantage over other conditional statements.