You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. For the last few years I've been working with C# and now using Dart and Flutter in personal and job projects.
And I feel the need in the interfaces as the aspect of Dart language.
I understand, that abstract classes provides the similar ways to get the guaranties about the interaction interface in the inherited children. But the interfaces will provides more strict understanding, about some entity behavior, and we could be sure, that our child won't inherit some useless behavior from the abstract parent.
The text was updated successfully, but these errors were encountered:
But the interfaces will provides more strict understanding, about some entity behavior, and we could be sure, that our child won't inherit some useless behavior from the abstract parent.
Are you saying you want a way to declare an interface that has no implementation so that the subclasses have to implement everything? You can acheive this by using implements instead of extends.
classA {
voidfunction() =>print("This is bad");
}
classBextendsA { } // inherits the bad functionclassBimplementsA { // doesn't inherit anything. It's an error not to implement the function@overridevoidfunction() =>print("This is good");
}
voidmain() {
A badClass =B();
A goodClass =C();
B.function(); // badC.function(); // good
}
That being said, the whole OOP design is currently being revisited, you may want to check out #1696.
If you create an abstract class with a private constructor, say C._noInstances() { throw UnsupportedError("No instances"); }, to inhibit adding the default constructor, then the class can only be used as an interface.
@lrhn and @Levi-Lesches, thank You for these samples. But I'm still thinking, that to have the interface as the language aspect will be much easier, than to do some additional manipulations. If the interfaces by default could be only implemented - it will help to build more clear project architecture. And as I see - it's not so difficult to implement, because the Dart has already working with such functional in abstract classes.
Hi. For the last few years I've been working with C# and now using Dart and Flutter in personal and job projects.
And I feel the need in the interfaces as the aspect of Dart language.
I understand, that abstract classes provides the similar ways to get the guaranties about the interaction interface in the inherited children. But the interfaces will provides more strict understanding, about some entity behavior, and we could be sure, that our child won't inherit some useless behavior from the abstract parent.
The text was updated successfully, but these errors were encountered: