You have an object that contains a list:
public class MyPojo {
private List<Object> list;
}
And you want to add an item to this pojo's list.
What's better ?
1) You add a getter, get the list and add an object to it
public class MyPojo {
private List<Object> list;
public List<Object> getList() {
return list;
}
}
// and then use
new MyPojo().getList().add(Object);
2) You write a addItem() in your Pojo that insert the object to the list
public class MyPojo {
private List<Object> list;
public void addItem(Object item) {
list.add(item);
}
}
// and then use
new MyPojo().addItem(Object);
What is the best pratice for code quality in this case ? Thanks !