-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add standard interfaces like Disposable as Mixins in the Dart SDK #59678
Comments
Summary: User requests standard interfaces (e.g., |
Just to point out the relation to issues like: |
as an addition this was my original issue on Listenable that was closed unfortunately |
For Flutter types specifically, flutter/flutter#149466 is the new issue to track |
Disposable is talked about here: #43490 |
I'll refer to #43490 for a disposable interface. For
I don't see a platform library provided serialization abstraction as a good choice. If it's not sufficient for anything in practice, it's a waste of code. If it's over-engineered (which is easy if you want to be sufficient for everything), then people will eventually choose a simpler version that matches their needs. Even if it gets just one thing wrong, you'll be better off using a different serialization approach. As for having to cast objects to abstract interface class Disposable {
void dispose();
}
extension StreamSubscriptionDisposableX on StreamSubscription<X> {
Disposable get disposable => _StreamSubscriptionDisposable(this);
}
final class _StreamSubcriptionDisposable implements Disposable {
StreamSubscription<Object?>? _subscription;
_StreamSubcriptionDisposable(this._subscription);
void dispose() {
_subscription?.cancel().ignore();
_subscription = null;
}
} and then you can wrap your objects when you create them and know their type, before passing them to something that wants to dispose them. |
@lrhn But reality is that we have throughout the Flutter SDK objects that already have a In relation to the |
One of the the great features of OO languages is polymorphism based on known interfaces.
Unfortunately, Dart has neglected to define interfaces that are standard in other SDKs. This makes it impossible to write generic libraries without casting objects to dynamic and try to call a method hoping it will be available, therefore hurting type safety.
The two most missed ones are probably
But I'm sure there might be some more. Thanks to mixins it should be possible to introduce such interfaces even today into existing classes of the Dart SDK, Flutter and all packages where it makes sense and improve the situation.
cc @FMorschel
The text was updated successfully, but these errors were encountered: