I have a similary class structure as below:
public class Foo extends Base{
...
}
public class Bar extends Base{
...
}
public class Aos extends Base{
...
}
public class Wrap{
List<Foo> getFooList();
List<Bar> getBarList();
List<Aos> getAosList();
}
Fold fooFold = getFooFold();
Fold barFold = getBarFold();
Fold aosFold = getAosFold();
// Code to refactor
for (Obj e : fooFold.getObj()) {
Foo foo = new Foo(.., .., ..);
for (Som s: e.getSom())) {
doSom();
}
wrap.getFooList().add(foo);
}
for (Obj e : barFold.getObj()) {
Bar bar = new Bar(.., .., ..);
for (Som c : e.getSom())) {
doSom();
}
wrap.getBarList().add(bar);
}
for (Obj e : aosFold.getObj()) {
Aos aos = new Aos(.., .., ..);
for (Som c : e.getSom())) {
doSom();
}
wrap.getAosList().add(aos);
}
How can i refactor the for-loops? (The for-loops are a "little" more complex. The logic do always the same. The iteration over the list, the creation of the object and adding the object to the list are different. )