Implicit interfaces
Every class implicitly defines an interface containing all the instancemembers of the class and of any interfaces it implements. If you want tocreate a class A that supports class B’s API without inheriting B’simplementation, class A should implement the B interface.
A class implements one or more interfaces by declaring them in animplements clause and then providing the APIs required by theinterfaces. For example:
1. // A person. The implicit interface contains greet().
2. class Person {
3. // In the interface, but visible only in this library.
4. final _name;
6. // Not in the interface, since this is a constructor.
7. Person(this._name);
9. // In the interface.
10. String greet(String who) => 'Hello, $who. I am $_name.';
11. }
13. // An implementation of the Person interface.
14. class Impostor implements Person {
15. get _name => '';
17. String greet(String who) => 'Hi $who. Do you know who I am?';
18. }
20. String greetBob(Person person) => person.greet('Bob');
22. void main() {
23. print(greetBob(Person('Kathy')));
24. print(greetBob(Impostor()));
25. }
Here’s an example of specifying that a class implements multipleinterfaces:
1. class Point implements Comparable, Location {...}
