public override void Add(MemoComponent mc) { // We might want to prevent looping here ... // since we can add any MemoComponent, we can // add a composite A to composite B, and then // composite B to A, making a loop between them // printing them out, results in a infintie loop // Maybe, a deep copy of the objects ??? try { if (!Contains(mc) && !mc.Contains(this)) { // This container does not have mc // and mc does not contain this // OK to add this.items.Add(mc); } } catch (InvalidOperationException ex) { // mc does not have the operation Contains // so it must be a Memo, not a MemoList. OK to add // Might want to log this ... this.items.Add(mc); } }
public virtual void Remove(MemoComponent mc) { throw new System.NotSupportedException( "Remove() not implemented for this class"); }
public virtual bool Contains(MemoComponent mc) { throw new System.NotSupportedException( "Contains() not implemented for this class"); }
public override void Remove(MemoComponent mc) { this.items.Remove(mc); }
public override bool Contains(MemoComponent m) { return this.items.Contains(m); }