V
VisionSet
[This isn't a web app question - this is just an analogy]
Consider a web application that requires user input from a <select> element.
with struts it is simple & usually logical to iterate through a collection
of options.
Typically we use a simple list of ints say 0 - 9 to represent our choice/s
and pass as parameter value/s.
This is just one example (often this arises not neccessarily in a web app
context), I ask myself is this the best solution to avoid duplication:
String[] choices = {"red","blue","yellow"};
if(choices[myParam].equals("red")) {} // do red stuff
<html>
<select> <!-- obviously this will be produced by iterating over choices -->
<option value="0">red</option>
<option value="1">blue</option>
<option value="2">yellow</option>
often this isn't neccessary, the collection can come naturally from another
class, that already has the ability.
Is this any good? Does anyone deal with this differently?
If iteration wasn't req'd then it would simply become:
public static final int MY_CONST = 5;
and no need for Strings at all!
Consider a web application that requires user input from a <select> element.
with struts it is simple & usually logical to iterate through a collection
of options.
Typically we use a simple list of ints say 0 - 9 to represent our choice/s
and pass as parameter value/s.
This is just one example (often this arises not neccessarily in a web app
context), I ask myself is this the best solution to avoid duplication:
String[] choices = {"red","blue","yellow"};
if(choices[myParam].equals("red")) {} // do red stuff
<html>
<select> <!-- obviously this will be produced by iterating over choices -->
<option value="0">red</option>
<option value="1">blue</option>
<option value="2">yellow</option>
often this isn't neccessary, the collection can come naturally from another
class, that already has the ability.
Is this any good? Does anyone deal with this differently?
If iteration wasn't req'd then it would simply become:
public static final int MY_CONST = 5;
and no need for Strings at all!