DART Classes
DART Classes
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
Purpose
Provide a way to reuse code in multiple class
hierarchies
Not a base class themselves
Purpose
Add new functionality to existing classes (even
those you don't own)
Purpose
Create classes that can be called like functions
Key Points
Instances can be called using instance() or just
instance EXAMPLE
Key Points:
Introduced in Dart 2.12 EXAMPLE