Should BidirectionalDictionary implement IDictionary

3 views
Skip to first unread message

Chris C

unread,
Jan 1, 2010, 10:15:07 AM1/1/10
to cadenza-list
At the moment BidirectionalDictionary`2 implements IDictionary`2 but
I'm not sure it should. The rational for this is that it doesn't
fulfill the contract for the values, namely the clause about "The
value can be null and does not have to be unique", which in this case
is not true.

Though on the other hand, although it doesn't completely fit the
contract for the interface, having it implement IDictionary`2 can be
useful for things like extension methods that only read values, etc.
It just requires the user understanding that it is a specialized
collection and thus does differ from the interface's contract.

The last option is for BidirectionalDictionary`2 not to implement
IDictionary`2 directly but have a property that exposes
BidirectionalDictionary`2 as an IDictionary`2 for convenience.

Personally I'm in favor of the current implementation as any user's of
a bidirectional dictionary have a specific reason to use it and should
understand the difference.

Reply all
Reply to author
Forward
0 new messages