DART CLASSES: A DEEP
DIVE
What are Classes?
Blueprints for creating objects
Define properties (data) and methods
(actions)
Fundamental building blocks of Dart
programs
INTRODUCTION
Why Use Classes?
Code organization and reusability
Encapsulation and data protection
Inheritance for building hierarchies
Polymorphism for flexible behavior
REGULAR CLASSES
(CONCRETE CLASSES)
The Basics
Most common type of class
Can be instantiated directly
Key Points
Can have constructors, instance variables, and
methods
EXAMPLE
Can extend other classes and implement interfaces
ABSTRACT CLASSES
Purpose
Define a common interface for its subclasses
Cannot be instantiated directly
Key Points
Can have abstract and concrete methods EXAMPLE
Subclasses must implement all abstract methods
MIXINS (WITH KEYWORD)
Purpose
Provide a way to reuse code in multiple class
hierarchies
Not a base class themselves
Key Points EXAMPLE
Can be used with the with keyword
Can only inherit from Object
EXTENSION METHODS
Purpose
Add new functionality to existing classes (even
those you don't own)
Key Points EXAMPLE
Introduced in Dart 2.7
A form of ad hoc polymorphism
CALLABLE CLASSES
Purpose
Create classes that can be called like functions
Key Points
Instances can be called using instance() or just
instance EXAMPLE
Useful for custom command-like behavior
INTERFACE CLASSES
Purpose
Define a contract for classes to follow
Specify a set of methods that implementing classes
must have
Can be implemented by multiple unrelated classes
Key Points:
Introduced in Dart 2.12 EXAMPLE
Methods in an interface are implicitly abstract
Classes implementing an interface must provide
concrete implementations for all methods
Regular (Concrete)
Abstract
SUMMARY OF Mixins
CLASS TYPES Extension Methods
Callable Classes
Interface Class
THANK YOU