4

So I ran into a programming philosophy issue and I was wondering what you think about this piece of code:

class Group {
private int nr;
//other fields

//getters/setters
}

private void renumberGroups(List<Group> groups) {
for (int i = 0; i < gruppen.size(); i++) {
gruppen.get(i).setNr(i + 1);
}
}

I want to manipulate a property of each datastruct in a list and I was wondering if doing it this way is okay. Deep in my heart I feel like it would be cleaner if I returned a deepcopy of the structure and make it so that the input isn't manipulated. But that seems a bit excessive to me.

Which approach would you take?

Comments
Add Comment