Table of Contents
# Declaring a Class
class class_name {
<fields>
<getters/setters>
<constructors>
<functions>
}
A class definition
Fields | A field is any variable declared in a class. Fields represent data pertaining to objects. |
Setters and Getters | Allows the program to initialize and retrieve the values of the fields of a class. A default getter/ setter is associated with every class. However, the default ones can be overridden by explicitly defining a setter/ getter. |
Constructors | Responsible for allocating memory for the objects of the class. |
Functions | Functions represent actions an object can take. They are also at times referred to as methods. |
Creating Instance of the class
var object_name = new class_name([ arguments ])
Accessing Attributes and Functions
//accessing an attribute obj.field_name //accessing a function obj.function_name()
# Dart Constructors
Class_name(parameter_list) {
//constructor body
}
Named Constructors
Class_name.constructor_name(param_list)
# Dart Class ─ Getters and Setters
Syntax: Defining a getter
Return_type get identifier
{
}
Syntax: Defining a setter
set identifier
{
}
# Class Inheritance
class child_class_name extends parent_class_name
Types of Inheritance
Single | Every class can at the most extend from one parent class. |
Multiple | A class can inherit from multiple classes. Dart doesn’t support multiple inheritances. |
Multi-level | A class can inherit from another child’s class. |