In Dart: extends vs. with vs. implements

amrazzam31

Amr Azzam

Posted on January 30, 2024

In Dart: extends vs. with vs. implements

šžš±š­šžš§šš¬: Use extends to create a subclass that inherits the properties and methods of a superclass. The new class will inherit all the properties and methods of the superclass and can add additional properties and methods of its own. For example, if you have a superclass called Animal, you might create a subclass called Dog that extends Animal.

š°š¢š­š”: Use with to mix in the behavior of a mixin into a class. A mixin is a class that provides a set of methods and properties that can be added to another class without creating a new subclass. This allows you to reuse code across multiple classes in a flexible way. For example, you might define a mixin called Logger that provides a log method, and then mix it into several classes that need logging behavior.

š¢š¦š©š„šžš¦šžš§š­š¬: Use implements to declare that a class conforms to a certain interface. An interface is a set of methods and properties that a class must implement in order to satisfy the interface. This allows you to write code that works with any class that implements the interface, without needing to know the specifics of each class. For example, if you have an interface called Drawable that specifies a draw method, you might declare that a class called Rectangle implements Drawable.

šŸ’– šŸ’Ŗ šŸ™… šŸš©
amrazzam31
Amr Azzam

Posted on January 30, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

23 - Observer
flutter 23 - Observer

June 21, 2021

22 - Mediator
flutter 22 - Mediator

June 14, 2021

20 - Chain of Responsibility
flutter 20 - Chain of Responsibility

May 31, 2021