Re: Chained call pattern with inheritance, polymorphism and generics...
Roedy Green wrote:
On Fri, 28 Sep 2007 01:04:57 -0000, Daniel Pitts
<googlegroupie@coloraura.com> wrote, quoted or indirectly quoted
someone who said :
The problem is, that I *want* to be able to access methods specific to
that type.
Otherwise I would return the abstract base class.
In that case you need to add them to the interface and implement them
with dummies, or else cast to specific classes or interfaces to use
them.
How? You don't know that specific types before use.
I can't think of any other mechanisms that would let you get
at the specific methods.
What's wrong then with pattern presented by Daniel to achieve that?
Similar pattern is successfully used by Enum (a base class "knows" the
type of its particular subclass). Why then not follow that here too?
I've used that pattern a few times in my own code. And (as I already
told in my previous postings to this thread) I see problem only with
enforcement of the appropriate type argument passed to the base class.
I don't know any other way to enforce that than the already described
one, i.e. checking it at run-time.
Nevertheless, the "pattern" itselve is nice, and useful IMHO. (Of
course, support for "ThisType" directly in the language would be nicer,
but that's definitely not the solution we can use today...)
piotr