Dart’s interfaces and classes provide you with a set of reusable and extensible building blocks. An interface defines a basic set of methods and constants, sometimes by inheriting from other interfaces. A class can implement multiple interfaces, but it only inherits from a single superclass.
The following example defines an interface, along with a class and subclass that implement it:
The following example defines an interface, along with a class and subclass that implement it:
interface Shape { num perimeter(); } class Rectangle implements Shape { final num height, width; Rectangle(num this.height, num this.width); // Compact constructor syntax. num perimeter() => 2*height + 2*width; // Short function syntax. } class Square extends Rectangle { Square(num size) : super(size, size); }
No comments:
Post a Comment