I'm creating a model where one element can contain other elements. I'm currently writing the interface to the model, and I'm not sure which is the best of the two options:
Option 1
interface Container {
List<Element> getElements(); // returns an unmodifiable list.
void addElement(Element e);
void removeElement(Element e);
}
Option 2
interface Container {
List<Element> getElements(); // returns an unmodifiable list.
void setElements(List<Element> elements);
}
What are the pros/cons of each option? Furthermore, are there "accepted" naming conventions in these cases, like using children
instead of elements
?