Dart Tutorial

Dart Chapter 7 of 15

Object-Oriented Programming

Model real things with classes and objects: constructors, inheritance, interfaces, mixins, enums, generics, extensions and more.

Dart is an object-oriented language through and through. This is the longest chapter in the course, and the one that matters most if you plan to build apps with Flutter, where every widget is a class.

Lessons in this chapter

  1. Classes and Objects in DartLearn object-oriented basics in Dart: define a class, create objects, and use fields, methods, this and toString with clear examples.
  2. Constructors in Dart: Default, Named, Initializer Lists and RedirectingEvery kind of generative constructor in Dart: default, initializing formals, named parameters, named constructors and initializer lists.
  3. Factory Constructors in DartLearn what a factory constructor is in Dart and when to use one: caching, singletons, returning subtypes and creating objects from JSON.
  4. Const Constructors in Dart: Immutable ObjectsLearn const constructors in Dart: create immutable, compile-time constant objects, understand canonicalization and why Flutter uses const.
  5. Getters and Setters in DartLearn getters and setters in Dart: computed properties, validating values, private fields, lazy getters and best practices.
  6. Private Members and Encapsulation in DartDart has no private keyword. Learn how the underscore makes members library-private, how privacy works across files, and best practices.
  7. Static Variables and Methods in DartLearn static members in Dart: static fields, static methods, constants, lazy initialization, and when to use them instead of instances.
  8. Inheritance in Dart: extends, super and @overrideLearn inheritance in Dart: create subclasses with extends, call the parent with super, override methods and pass constructor arguments.
  9. Abstract Classes and Methods in DartLearn abstract classes in Dart: define methods without a body, force subclasses to implement them, and share common code.
  10. Interfaces in Dart: The implements KeywordDart has no interface keyword for declarations: every class is an interface. Learn implements, multiple interfaces and when to use them.
  11. Mixins in Dart: Reusing Code with the with KeywordLearn mixins in Dart: share methods between unrelated classes using mixin and with, restrict them with on, and understand ordering.
  12. Polymorphism in Dart: One Interface, Many FormsUnderstand polymorphism in Dart with examples: method overriding, dynamic dispatch, interface-based polymorphism and type checks.
  13. Enums in Dart: Simple and Enhanced EnumerationsLearn enums in Dart: define a fixed set of values, use them in switch, and add fields, methods and constructors with enhanced enums.
  14. Extension Methods in DartAdd new methods and getters to existing types in Dart with extensions, including String, int, List and nullable types.
  15. Extension Types in Dart: Zero-Cost WrappersLearn extension types in Dart: wrap an existing type in a new, distinct type with no run-time cost for safer IDs, units and APIs.
  16. Generics in Dart: Type-Safe Reusable CodeLearn generics in Dart: generic classes, functions and constraints with extends, plus covariance and the covariant keyword.
  17. Object Equality in Dart: ==, hashCode and identicalLearn how equality works in Dart: identity versus value equality, overriding == and hashCode correctly, and why it matters for Set and Map.
  18. Class Modifiers in Dart 3: base, interface, final, sealed and mixinUnderstand Dart 3 class modifiers. Learn what abstract, base, interface, final, sealed and mixin allow and when to use each one.
  19. Operator Overloading and Callable Classes in DartDefine how operators such as +, -, ==, [] and < work on your own classes in Dart, and make objects callable with the call method.