I realized with my last bit of coding/post that i was following one of the rules that jay had told me about: “Once you've written the tests, provide the simplest implementation that makes them pass”.  However, when writing a library it's a little unclear what that means.  Do i provide the simplest implementation of an ArrayCollection that makes this pass? Or do i just provide the simplest implementation of an ICollection that makes this pass.  In either case I didn't do that.  The simplest implementation i think i could come up with would be to do:

    class Collection<A> : ICollection<A>


        bool empty = true;


        #region ICollection<A> Members


        public bool Add(A element) {

            empty = false;

            return true;



        public bool Empty {

            get {

                return empty;






Part of me cringes at this.  But for the life of me, the more i think about it, the more I like it.  If my interface only allowed me to observe the state of the collection through “Empty” and it only allowed me to affect that state through “Add” then this really is the simplest implementation.  Why did i build up that A[]/count state in the earlier example?  They overly complicated things and they required me to implement a complex algorithm with many areas for error.

Of course, this implementation wouldn't scale when i started adding more methods and invariants on the interface.  But i think i should do the fixing up then rather than now.