I'm trying to figure out the "best" way to implement a strongly typed
ArrayList. Using inheritance is one approach. It has the advantage that I
only have to write overrides for the Add method and indexer. There are
problems with this however. First the indexer "override" has a different
return type. This doesn't cause a compile time error, but using the indexer
doesn't seem to produce a properly typed expression. The Add override must
have an arg of type object so the method doesn't reflect the strong
typing -- until run time when the my hand coded type check is run. I've
added an Add overload that uses a strongly typed arg, but the original
method still appears in the command completion popup.
An alternative approach would be to use composition, but this requires that
I implement wrapper methods for all of the ArrayList methods that I want to
make available in the strongly typed ArrayList class.
I think the latter (composition) approach provides the best solution in
terms of providing a truly strongly typed object, but am bothered by the
need for the "duplicate" methods.
Is there another alternatives, suggestions?
Thanks in advance,
Bill