I suggest that you apply the following order and principles
when working on composite projects.
Allow the client to control invocation of the addition and
Get the additions and then the removals right.
Then deal with the each Implementation-specific
functionality, one at a time.
So, if we are dealing with find-accomodation, deal with
find-accomodation across component, composite and leaf. Then move on to deal
with bookings across component, composite and leaf. Finally, move on to unbooking
across component, composite and leaf
Deal with subsidiary functions first. So for example, deal
with the find-accomodation first. This is used before you can do the booking,
so in the same way that we would be guided by general software development
principles to deal with it first (composing bigger functionality from primitive
functions), similarly, would we do it here.
Test the solution thoroughly. Remember you are not done
coding until you have tested and this holds true for every software project.
Now you will notice that Composite can be a real pain to
test, since you have to repeatedly create composites and leaves before you can
test operations on them. And depending on the number of functionalities you
have to test, this can be horrendous.
My suggestion is to create the object-hierarchy of test-data
and include a routine which uses some persistence mechanism to persist-to-disk
and restore the hierarchy (possibly with an option to restore from several
backups). You can then make changes to it, tweak it, add test cases and remove
extraneous stuff. In-between tests, you persist the object-hierarchy. This not
only saves you time and frustration (plus allowing other developers to code and
test the solution simultaneously), but it also helps you to ensure consistency
in the tests.
Composite/Treeview/XML: a natural fit
Composite is one of the most elegant and intuitive patterns.
Later on when we look at the Interpreter pattern, you will see where it can
save you from knowing a lot of XPATH. I load the XML file straight into a
composite object-hierarchy which is linked to a treeview, do all the processing
in the Composite hierarchy (including searching) and then store the results
back into XML.