Cyrus enhances Optional<>
Cyrus just can’t stop! First he Refactored Optional<>, basically to use a singleton for None<>
interface IOptional<A>
{
A Value { get; }
}
class None<A> : IOptional<A>
{
public static readonly IOptional<A> Instance = new None<A>();
private None() { }
A IOptional<A>.Value
{
get { throw new InvalidOperationException(); }
}
}
class Some<A> : IOptional<A>
{
readonly A value;
public Some(A value)
{
this.value = value;
}
A IOptional<A>.Value
{
get
{
return value;
}
}
}
He kept getting annoyed with himself for having an interface with only one method (IOptional), as that’s a smell that you need a delegate. I insisted that an interface is the right thing, because a delegate isn’t just a single-method interface – it also is just about “shape”. That is, a method with the right signature can satisfy a matching delegate, but you can’t satisfy an interface with a class unless you actually inherit from that interface.
To put it another way: methods don’t inherit from delegates.
Or yet another: inheritance counts from something.
He finally agreed and let it be.