Skip to content

No convenient way to introduce new functionality to existing types. #40

@lrhn

Description

@lrhn

Current status: being addressed via #41


The author of a Dart class can add more features to the class, but down-stream clients cannot easily do so.

To work with an existing class, you can write a static helper function, but it's much less convenient to call that as a function than as a method on the object. Example: helper(foo.something).somethingElse is harder to read and understand the sequencing of than foo.something.helper().somethingElse.

The best current option is to wrap the existing class in a new class which forwards members to the wrapped object, and then adds some more operations on top. It adds overhead and requires an explicit wrapping operation.

Other languages solve this problem in various ways, including extension methods and pipe operators.

Dart should do something to make it easier for users to add easily usable functionality to existing classes.

Metadata

Metadata

Assignees

Labels

requestRequests to resolve a particular developer problem

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions