// // This file contains the C# code from Program 5.13 of // "Data Structures and Algorithms // with Object-Oriented Design Patterns in C#" // by Bruno R. Preiss. // // Copyright (c) 2001--2002 by Bruno R. Preiss, P.Eng. All rights reserved. // // http://www.brpreiss.com/books/opus6/programs/pgm05_13.txt // public abstract class AbstractContainer : ComparableObject, Container { protected int count; private class ToStringVisitor : AbstractVisitor { StringBuilder builder = new StringBuilder(); private bool comma = false; public override void Visit(object obj) { if (comma) builder.Append(", "); builder.Append(obj); comma = true; } public override string ToString() { return builder.ToString(); } }; public override string ToString() { Visitor visitor = new ToStringVisitor(); Accept(visitor); return GetType().FullName + " {" + visitor + "}"; } // ... }