Copying complex data structures in Java

looksau

New Member
I am using Composite pattern in my Java program, such that a Component is being extended by three classes. [*]Leaf class extends Component[*]Composite extends Component[*]Decorator extends Component (for decorating leafs)The composite is currently implemented using a List, where each element can either be a leaf, another Composite or a decorator. I am thinking of adding undo/redo functionality for which I am going to be using Command/Memento patterns. Now my question, how can I create a deep copy of my list here, so that I can restore it later? Basically, need to find a way that allows me to create a new identical copy of my list at the current time before executing another command. I am thinking there has to be some recursive way of doing it. I wish I could post snippets of code, but unfortunately cannot because of confidentiality reasons. Thanks
 
Back
Top