Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interface abstract class vs abstract class different

What is the difference between the interface abstract class and the simple abstract class in the current Dart 3.0 version, which one is better and what are the possibilities of both?

I did not notice the difference between the two, but they asked it as a question in the company

like image 871
Abduraimov Muhammadyusuf Avatar asked Sep 08 '26 10:09

Abduraimov Muhammadyusuf


1 Answers

I assume you are asking about differences in those two declarations:

abstract interface class BaseInterface {}
abstract class BaseClass {}

In Dart, classes have implicit interfaces and all classes can be used as interfaces. So both of those can have declarations, implementations and be used in implements sections.

interface keyword in Dart:

Libraries outside of the interface’s own defining library can implement the interface, but not extend it.

https://dart.dev/language/class-modifiers#interface

So in short BaseInterface can not be extended. It can help you enforce user of this class to use it as classic OOP interfaces are intended to be used.

More info: https://dart.dev/language#interfaces-and-abstract-classes

like image 71
fsw Avatar answered Sep 09 '26 23:09

fsw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!