How do I find the actual types of the elements in a list of classes?

Jack Stouffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 13 16:48:05 PDT 2015


On Thursday, 13 August 2015 at 22:49:15 UTC, Adam D. Ruppe wrote:
> On Thursday, 13 August 2015 at 21:42:54 UTC, Jack Stouffer 
> wrote:
>> dynamically calling different methods on each object in the 
>> list based on its type.
>
> The cleanest OO way of doing that is to put the methods you 
> need in the interface and always call it through that. Then 
> there's no need to cast and each child class can implement it 
> their own way.

This really doesn't make sense in the context that I am using 
this code in. The above code is a very reduced test case. In my 
code, the list can have 20-30 different types of classes in it 
all inheriting from the same interface, and it doesn't make sense 
for all of those classes to implement a method that is very 
specific to one of the classes.


More information about the Digitalmars-d-learn mailing list