Description
Since the new addition of sealed, base and other OOP keywords,
dart offers more ways to model real world systems.
When using inheritance it is common pattern in chain of command as an exemple
to ask if a class is a subclass of specific parent to switch implementation.
Kotlin expose isSubclassOf
, java Class.isAssignableFrom
, etc
I'm now facing a case where I need to handle a structure in parallel with the
classes declarations to handle hierarchy and it's getting large and error
prone to manually manage each new entry per class.
On Flutter Forum user tenhobie suggested this:
bool typeIsSubtypeOf<T1, T2>(T1 _, T2 __) => <T1>[] is List<T2>;
that works on simpler cases only.
When moving away from flutter and trying to model business relying on OP
this would be a considerable addition for large code base simplification.
Thank you for your feedbacks.