Article image Introduction to Object-Oriented Programming on Dart: Introduction to Object-Oriented Programming

5.1. Introduction to Object-Oriented Programming on Dart: Introduction to Object-Oriented Programming

Page 57 | Listen in audio

Object-Oriented Programming (OOP) is a programming paradigm that uses "objects" - which can contain both data and code: data in the form of fields (also known as attributes or properties), and code, in the form of procedures ( also known as methods). OOP is a way of structuring programs so that properties and behaviors are grouped into individual objects. Dart is a language that supports OOP and is therefore an excellent choice for developing Flutter applications.

To begin with, let's understand what an object is. An object is an entity that has state and behavior. It is an instance of a class. For example, if you have a class called 'Car', then 'Car1', 'Car2', etc., are instances of the 'Car' class and are objects. An object's state is stored in fields (also known as variables), while methods display the objects' behavior.

Moving forward, a class is a template for creating objects. Defines the state and behavior that all objects of the class type share. For example, the 'Car' class might have fields like 'color', 'model' and 'make', and methods like 'accelerate', 'brake' and 'turn'.

In addition, OOP in Dart also involves concepts such as inheritance, polymorphism, and encapsulation. Inheritance is a process where one class acquires the properties and behaviors of another class. The class that is inherited is called a 'superclass' or 'parent class', and the class that inherits is called a 'subclass' or 'child class'. Dart supports single inheritance, which means that a class can only inherit from a single class.

Polymorphism is a concept where a name can have many forms. For example, if we have a parent class 'Animal' and subclasses 'Dog' and 'Cat', then based on polymorphism we can have a method 'emitSound' which will do something different in class 'Dog' and in class 'Cat' .

Encapsulation is a concept where implementation details are hidden and only functionality is provided to the user. In Dart, this can be achieved using access modifiers - 'private' and 'public'. If a field or method is declared 'private', it can only be accessed within the class where it is declared. If it's 'public', it can be accessed from anywhere.

To create Flutter applications, it is important to understand and apply these OOP concepts in Dart. This will help create more efficient and maintainable applications as OOP promotes code reuse and modularity.

To conclude, Object Oriented Programming is a powerful programming paradigm that provides a clear and flexible framework for building complex programs. Learning OOP in Dart will not only make Flutter application development easier, but will also give you a solid foundation for learning and using other object-oriented programming languages.

Now answer the exercise about the content:

Which of the following Object Oriented Programming (OOP) concepts is defined as a process in which one class acquires the properties and behaviors of another class?

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image Introduction to Object Oriented Programming in Dart: Classes and Objects

Next page of the Free Ebook:

58Introduction to Object Oriented Programming in Dart: Classes and Objects

3 minutes

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or App Store!

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text