I'm currently reading the reference manual and have some thoughts considering the parent/child model in chapter 9 (version 2.1.1). I want to use the principles in the example (9.2), but I also want to make sure nobody adds a child without calling addChild() but instead getChildren().add() - and thus possibly not setting the parent. Therefore I am thinking I would modify getChildren() to return an unmodifiable Set instead.
Code:
public class Parent {
...
private Set children
...
public Set getKittens() {
return java.util.Collections.unmodifiableSet(kittens);
}
public void addChild(Child c) {
c.setParent(this);
children.add(c);
}
}
For the mapping to work properly, I assume I need to set
Code:
access="field"
on the property. (access="field" works for private properties, right?)
Would this generally be a good idea?
Could it cause any problems with lazy initialization?