Skip to content

Expose isSubclassOf #58261

Open
Open
@Solido

Description

@Solido

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-coretype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions