Unit 3 ADAD
Unit 3 ADAD
● Classes:
○ A class is a blueprint or template for creating objects. It defines the
properties (fields) and behaviors (methods) that objects of that class will
have.
○ In Dart, you define a class using the class keyword.
Example:
Dart
class Car {
String make;
String model;
int year;
void startEngine() {
print('Engine started');
}
}
○
● Objects:
○ An object is an instance of a class. It represents a specific entity with the
properties and behaviors defined by its class.
○ You create objects using the new keyword (though it's optional in modern
Dart).
Example:
Dart
void main() {
var myCar = Car(); // Creates an object of the Car class
myCar.make = 'Toyota';
myCar.model = 'Camry';
myCar.year = 2023;
myCar.startEngine();
}
2. Encapsulation:
● Encapsulation is the principle of bundling data (fields) and methods that operate
on that data within a single unit (a class).
● It also involves controlling access to the internal state of an object, often using
access modifiers.
● In Dart:
○ By default, members (fields and methods) are public.
○ To make a member private, prefix its name with an underscore (_). Private
members are accessible only within the library where they are declared.
○ Getters and setters are often used to control access to private fields.
Q.8) Explain App Structure and Navigation in Flutter.