My goal is to create an object using the Composite Design Pattern that can be marshaled into XML using JAXB. In addition, in my case, it seems desirable for the composite component to use a Set (e.g., LinkedHashSet) to ensure that no duplicate elements are stored. However, I can only find examples of the Composite Design Pattern that use ArrayList (see below).
Is there a conceptual reason why it would not be possible, or desirable, to use a LinkedHashSet in a Composite Design Pattern. Otherwise, can someone explain how to implement the Composite Design Pattern using a LinkedHashSet? I assume this would require using an Iterator on the LinkedHashSet, but I have not been able to figure out a way to provide the get(int i) functionality of ArrayList with .next() functionality of the LinkedHashSet.
Aucun commentaire:
Enregistrer un commentaire