Introduction to Object Oriented Programming
Understand the concept of object oriented programming in dart
Introduction to Object Oriented Programming
Dart is high-level programming language with the support of object-oriented programming. Dart is pretty similar to Java, C#, and C++ in terms of syntax and features. Many concepts in Dart are similar to Java, C#, and C++.
Familiar with the topic? Play Quiz
Pillars of Object Oriented Programming
Object-Oriented Programming (OOP) is built upon several fundamental principles, often referred to as the “Pillars of OOP.”
These pillars encapsulate the key concepts and practices that guide the design and implementation of object-oriented systems. The core concepts of OOP is language independent, if you have strong foundations of OOP its similar to any programming language.
There are four pillars of Object Oriented Programming.
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
Encapsulation
Definition
Encapsulation is the bundling of data (attributes or properties) and the methods (functions or procedures) that operate on the data into a single unit known as class . It involves restricting access to some of an object’s components, emphasizing the idea of data hiding.
In simple terms, it is the process to hide a complex logics behind and exposing the packed solution. Just like, components in capsule of anti-biotic is not exposed but we know it treats the fever. Here the components will be methods and properties of a packed capsule class.
Purpose
Encapsulation promotes the principle of information hiding, reducing the complexity for users of a class by exposing only what is necessary.
It helps in preventing unauthorized access and modification of data, enhancing the robustness and security of the code.
Inheritance
Definition
Inheritance is a mechanism that allows a new class (subclass or derived class) to inherit properties and behaviors from an existing class (superclass or base class). The new class can then extend or override the inherited features
In simple terms, Inheritance is the process of passing on properties from one class (generation) to another. For example, a child inherits the properties of his/her parents and grandparents which continues this from generation to generation. Likewise, a child can have changes to the properties passed by the ascentors. This way a inherited class can make changes to the properties or methods, called method overriding
Purpose
Inheritance facilitates code reuse, promoting a hierarchical structure where common attributes and methods are defined in a base class. This results in more maintainable and modular code, as changes made to the base class automatically affect all derived classes.
It helps in preventing unauthorized access and modification of data, enhancing the robustness and security of the code.
Polymorphism
Definition
Polymorphism means “many forms” and refers to the ability of objects to take on multiple forms. In OOP, polymorphism manifests in two main types: compile-time polymorphism (method overloading) and runtime polymorphism (method overriding).
In simple terms, you can have different forms.
Purpose
Encapsulation promotes the principle of information hiding, reducing the complexity for users of a class by exposing only what is necessary.
It helps in preventing unauthorized access and modification of data, enhancing the robustness and security of the code.
Abstraction
Definition
Abstraction involves simplifying complex systems by modeling classes based on their essential characteristics while ignoring unnecessary details. It often involves the creation of abstract classes and interfaces that define a blueprint for concrete classes.
In simple terms, it is the process to define the structure of the class. Its like building the base for the building where every floor will have the same width as base.
Purpose
Abstraction helps manage complexity by focusing on the essential features of an object and hiding the irrelevant details. It enables developers to create generalized models that can be extended or implemented by specific classes, fostering a clear and understandable architecture.
Quiz
Let’s play the quiz!