Key points are:
Junior developers starting to work with Swing trees usually
make one similar mistake. Swing Tree API forces them to make
all changes to a tree by calling methods on TreeModel. They don't
respect this rule and make changes to a node directly. For example
by calling node.insert() on it. Then they wonder why their model's
visual representation (JTree) has not changed. Take a look for
example at this thread
Let's move into theory a little. You want your classes to remain in consistent state after any method you invoked. You have the possibility to put you system into inconsistent state, for example, by adding new node to a node using node.insert(newNode). Your TreeModel will not be notified, your visual tree representation will not be presenting actual information. This inconsistent state is something we need to avoid.
Furthermore, object-oriented design teaches us to design objects which would be responsible for its own data. So it would be logically to let a node to manage its children and no need to worry about TreeModel.
Have thoughts? We want to hear from you! Contact us on our forums.