1. Introduction
In object-oriented programming (OOP), classes serve as the fundamental building blocks for creating objects. A class acts as a blueprint that defines the properties (data) and behaviors(methods) that its objects will possess.
By using classes, Dart allows programmers to organize related variables and functions into a single logical unit. This approach supports core OOP principles: abstraction, encapsulation, inheritance, and polymorphism, making applications easier to manage and scale.
2. Structure and Syntax of a Class.
A class in Dart defines the structure of an object by grouping related data (variables) and behavior (methods) together.
Each class can include:
Instance variables – attributes or data that belong to each object.
Constructors – special functions that initialize new objects.
Methods – functions that define how an object behaves.
Below is an example of a simple Dart class definition:

The class Person defines a blueprint for creating Person objects.
It’s important to note that in the instance variables String? name, age, the ? symbol indicates that the string is nullable, meaning it can hold either a string value or null, and the constructor initializes the variables name,gender, and age whenever a new object is created.
As demonstrated in the image below inside the main function:

The showdata() method above prints out information about the person and the variable p1 creates a new instance of the Personclass with name set to “Raph,” genderto “male,” and age to 24.
When the code is executed, the expected output will be:
![]()
3. Creating and Using Objects in Dart
Once a class is defined, we can create objects from it.
An object is a specific, usable copy of a class that stores real data in memory.
You can think of a class as a blueprint, and each object as a real product built from that blueprint (class).To illustrate,follow the simple Car class.
The Car class serves as a blueprint for creating objects. As demonstrated below in the main() function:
Here, car1 and car2 are objects created from the Car class. You can create as many objects as needed, each with its own set of values for the properties defined in the class.
When the code is executed, the expected output is:
![]()
4. Constructors
A constructor is a special method in Dart that is automatically called when an object of a class is created.
Its main purpose is to initialize object properties and prepare the instance for use. Some of the existing constructors are:
4.1 Generative Constructors
A generative constructor is the most common form. It creates a new instance every time it is called. This type allows initializing instance variables either directly or through parameters.
Here, every time you call Student(name age ), a new Student obeject is created.

The expected output
![]()
4.2 Default Constructor
If no constructor is not explicitly defined, Dart automatically provides a default constructor that takes no arguments and does nothing other than create the object.
In the image above there are no constructors defined in the class Animal. But you create an object like so:
It is possible to create objects since dart provides a default constructor and if we call the method a.speak(). the expected output is;
4.3 Parameterized Constructor
A parameterized constructor allows you to pass data when creating an object.
This is the most common constructor type in Dart.

When you create an object or 2 then call the method.

The expected out-put is.
![]()
5. Methods in Dart
Methods are functions that belong to a class and define the behavior of its objects. They enable objects to perform actions, manipulate data, or communicate with other objects.
Dart supports two main categories of methods: instance methods and class (static) methods.
5.1 Instance Methods
An instance method operates on the data of a specific object.
To call an instance method, one must first create an instance of the class.

Here, displayInfo() is an instance method because it depends on the instance’s name and marks. Each Student object created has its own version data.(the instance method is called on instance variables in this case name and marks)
5.2 Static (Class) Methods
A static method belongs to the class itself, not to any object. It is declared using the static keyword and can be called directly using the class name.
Static methods cannot access instance variables or instance methods directly — they can only work with static variables or parameters passed to them.
In this case static double squarethat pick up the double num as it’s argument and when the method is called:
![]()
The expected output is ;
![]()
6. Extending a Class (Inheritance)
Sometimes, you’ll want one class to build upon another. That’s where inheritance comes in. Inheritance allows you to create a new class that reuses, extends, or modifies behavior of another class.

When you create a Dog object, it inherits the behavior of Animal.

You can override parent methods using @override.
7. Mixins
Inheritance isn’t the only way to share behavior Dart also supports mixins for more flexible code reuse. A mixin is a way to reuse code between classes without using inheritance.
Think of it as “copy-pasting” shared methods into multiple classes safely.

Important points to note about mixins.
- You use them with the with keyword.
- They don’t have constructors.
- You can combine multiple mixins.
Mixins are great for sharing behavior across unrelated classes.
8. Enums
Enums (short for enumerations) are a way to represent a fixed number of constant values.

Since Dart 2.17+, enums can contain methods, getters, and fields.

Enums are perfect for representing states, modes, or fixed categories.
9. Extension Methods
An extension method lets you add new behavior to existing types — without changing their source code.
10. Callable Objects
In Dart, you can make a class callable like a function by defining a call() method.

Callable objects are especially useful when you want function like behavior but still need the structure of a class (for example, in state management or data transformers).
Reflection
As I worked through these concepts, I realized that OOP in Dart is not just a set of rules—it’s a mindset. It encourages me to think more abstractly about problems, break them into manageable pieces, and design solutions that are both reusable and scalable.
OOP features has allows me as a developer to approach Dart projects with a clearer structure, a stronger understanding of code organization, and a deeper appreciation of how to model real-world scenarios efficient way. This journey has not only expanded my technical skill set but has also shaped my thought process toward writing cleaner, more intentional code.








