Interfaces How implicit interfaces work in Dart

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.
Get Unlimited PRO Access

OR


*Enrollment provides full access to this course (and updates) for life.

An interface is a contract that a class must follow. Prefixing a method or variable with _ makes it private, so it won’t be visible when imported from a different file.

file_type_dartlang interfaces.dart
class Elephant {
  // Public interface
  final String name;

  // In the interface, but visible only in this library. (private)
  final int _id = 23;

  // Not in the interface, since this is a constructor.
  Elephant(this.name);

  // Public method.
  sayHi() => 'My name is $name.';

  // Private method.
  _saySecret() => 'My ID is $_id.';
}

Questions?

Ask questions via GitHub below OR chat on Slack #questions