Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Turns out there was an even simpler way to write a concrete implementation of ICollection:
namespace Testing.Collections
{
public class EmptyCollection<A> : ICollection<A>
{
public EmptyCollection() {
}
#region ICollection<A> Members
public bool Add(A element) {
return false;
}
public bool Empty {
get {
return true;
}
}
#endregion
}
}
I thought of this implementation after the conversation I had with Julien Covreur (concerning Weak/StrongReferences) regarding the Replace Type Code with Subclasses refactoring. I'm not a big fan of either state or mutability of objects and i prefer to have both fall out of the system naturally through the use of inheritance.
Note: because there is no state and no mutability, this object is a prime candidate for the singleton pattern. That, of course, can come at a later time.
Comments
- Anonymous
May 17, 2004
"Couvreur" ;-) - Anonymous
September 02, 2005
Veri nice site! - Anonymous
May 31, 2009
PingBack from http://patiochairsite.info/story.php?id=345