Je suis en train de refactoriser un ancien code. Je cherche des directions sur le meilleur modèle de conception à utiliser ici. Je pense au modèle d'usine mais je ne suis pas sûr que ce soit la meilleure façon d'y aller ou pas.Comment refactoriser ce code
Voici donc un bref aperçu du pseudocode. La classe Foo a la logique métier de base.
Class Foo{
private List<Things> stuff;
private static Integer count;
//getter setter for stuff
public Foo(List<Things> stuff){
this.stuff = stuff;
this.count=1;
}
//the following 3 methods are 90% similar
public List<Newthings> doSomeThingFirst(){
//uses the list stuff and also increments the static member count for each entry in List<NewThings> based on certain conditions
}
public List<Newthings> doSomethingSecond(){
//uses the list stuff and also increments the static member count for each entry in List<NewThings> based on certain conditions
}
public List<Newthings> doSomethingThird(){
//uses the list stuff and also increments the static member count for each entry in List<NewThings> based on certain conditions
}
//in the future there may be doSomethingFourth(), doSomethingFifth() ... etc.
}
The caller of class Foo looks something like below.
Class SomeServiceImpl{
public List<Things> getAllFoo(List<Things> stuff){
Map<Integer,NewThings> fooList = new HashMap<Integer,NewThings>();
Foo foo = new Foo(stuff);
fooList.put(1,foo.doSomeThingFirst());
fooList.put(2,foo.doSomeThingSecond());
fooList.put(3,foo.doSomeThingThird());
return new ArrayList<Things>(fooList.values());
}
}
Permettez-moi de savoir comment pensez-vous que ce code devrait être refactorisé pour maintenabilité et de réutiliser ou est-ce bien comme il est?
Merci pour vos contributions.
Mon Java est rouillé, mais ArrayList prend deux arguments de type? Que diable pour? –
Mon mauvais. J'essayais de faire un code pseudo sur le code actuel et j'ai tapé une liste au lieu d'une carte. – CoolBeans
Impossible de comprendre votre code. Aussi, il semble y avoir beaucoup d'erreurs de codage – YoK