[Evolution] meilleur choix?
Bonjour,
c'est en relisant une de mes classes que je me pose la question :
que faut il mieux utiliser dans le cas de variable fixe static :
avant jre 1.5 j'utilisai :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
public static final int IN_LISTEN = 0;
public static final int ERROR_LISTEN = 1;
public static final int BOTH_LISTEN = 2;
...
public JRuntimePanel(ProcessObject p, int type) {
...
switch (type){
case IN_LISTEN :
for(int i=0;i<po.getInList().size();i++)
addText(po.getInList().get(i));
break;
case ERROR_LISTEN :
for(int i=0;i<po.getErrorList().size();i++)
addText(po.getErrorList().get(i));
break;
case BOTH_LISTEN :
for(int i=0;i<po.getInList().size();i++)
addText(po.getInList().get(i));
for(int i=0;i<po.getErrorList().size();i++)
addText(po.getErrorList().get(i));
break;
} |
et maintenant j'ai tendance a utiliser :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
public static enum TYPE{
LISTEN_IN,
LISTEN_ERROR,
LISTEN_BOTH
};
...
public JRuntimePanel(ProcessObject p, TYPE type) {
switch (type){
case LISTEN_IN :
for(int i=0;i<po.getInList().size();i++)
addText(po.getInList().get(i));
break;
case LISTEN_ERROR :
for(int i=0;i<po.getErrorList().size();i++)
addText(po.getErrorList().get(i));
break;
case LISTEN_BOTH :
for(int i=0;i<po.getInList().size();i++)
addText(po.getInList().get(i));
for(int i=0;i<po.getErrorList().size();i++)
addText(po.getErrorList().get(i));
break;
} |
Niveau code je m'y retrouve mieux avec la seconde methode (qui force d'avoir une valeur prevue donc plus sure). mais je me pose la question maintenant de savoir s'il y a des contre indications.