Polymorphism

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Fundraising

event plan
Emerald View Elementary School

Abanoub Ezzat
Introduction to Object-
Oriented Programming
(OOP)
Object-Oriented Programming (OOP)
is a programming paradigm
that organizes code around
the concept of objects
Objects are instances of classes
that encapsulate data and behavior
OOP allows for code to be organized
into reusable, modular units,
making it easier to maintain and extend

Abanoub Ezzat 2
OOP is based on four fundamental
principles

Encapsulation: the ability to hide the


internal details of an object and expose
only what is necessary
Inheritance: the ability for a class to
inherit properties and methods from a
parent class

Polymorphism: the ability for objects of


different types to be treated as if they were
the same type

Abstraction: the ability to focus on the


essential features of an object while
ignoring the details
Abanoub Ezzat 3
Polymorphism
is a key feature of object-oriented programming (OOP)

In OOP, Polymorphism allows objects of different types

to be treated as if they were the same type

This means that a single method or operation

can be applied to multiple types of objects

Abanoub Ezzat 4
Inheritance
Inheritance is the process by which a class inherits
the properties and methods of another class
Inheritance allows for a parent class to be used as
a blueprint for creating child classes
Polymorphism can be achieved through
inheritance by using a parent class
as a parameter type in a method,
and passing in child classes as arguments

Abanoub Ezzat 5
Example of Polymorphism
through Inheritance in Dart
Suppose we have two classes,
Shape and Circle.
Circle is a child class of Shape and
inherits properties and methods from it.
We also have a drawShape() function
that takes an object of the Shape class
as an argument and calls its draw() method.

Abanoub Ezzat 6
Example of Polymorphism
through Inheritance in Dart
Now we can create objects of both
the Shape and Circle classes
and pass them to
the drawShape() function:

Abanoub Ezzat 7
Example of Polymorphism
through Inheritance in Dart

Even though shape and circle are of different types,


they can both be passed to the drawShape() function
because they both inherit from the Shape class and have a draw() method.
When the drawShape() function is called with shape, it calls the draw() method
of the Shape class and outputs "Drawing a shape.".
When it's called with circle, it calls the draw() method of the Circle class
and outputs "Drawing a circle.".

8
Abanoub Ezzat
Example of Polymorphism
through Interfaces in Dart
Interfaces are a contract that defines
the properties and methods that a class
must implement
Dart interfaces allow for Polymorphism
by allowing objects of different classes
to be treated as if they implement the
same interface
This means that objects can be treated
as if they have the same properties
and methods, even if they are of different types
Abanoub Ezzat Fundraising event plan 9
Example of Polymorphism
through Generics in Dart
Generics allow for the creation
of reusable code that can work with
a variety of different types
Dart's Generics allow for Polymorphism
by allowing objects of different type
s to be used interchangeably
in generic code
This means that a single method or class
can work with a variety of different types,
without having to be rewritten for each type
Abanoub Ezzat Fundraising event plan 10
Conclusion and Speaker
Introduction
In conclusion, polymorphism is a powerful
feature of object-oriented programming
that allows for greater code flexibility My name is Abanoub Ezzat

and modularity and I am a Flutter developer

In Dart, polymorphism is achieved through with 2 years of experience

the use of inheritance, interfaces,


and generics

Abanoub Ezzat 11

You might also like