POLY MORPHISM OBJECT ORIENTED CONCEPT Team DURNIBAR
Encapsulation Abstraction Inheritance Polymorphism PILLERS OF OOP
Abdul Ahad Nur ID: 0242310005341227 Dept. of Software Engineering S. M. Hasib Hasnain ID: 0242310005341116 Dept. of Software Engineering Sarowar Mahfuz Suman ID: 0242310005341345 Dept. of Software Engineering Md Nahid ID: 213-35-809 Dept. of Software Engineering Sazid Hossain ID: 0242310005341328 Dept. of Software Engineering OUR TEAM Team DURNIBAR
POLY MORPHISM Greek Words POLY + MORPHS MANY + FORMS MEANING OF POLYMORPHISM
EXAMPLE OF POLYMORPHISM Polymorphism: A person can 'eat' in different ways - with chopsticks, a fork, or hands - but the action remains 'eating'."
PETER is also Polymorphic !!! A high school student, Peter goes to school , and hang out with friends . As Spider Man, he bashes up buddies . Peter has multiple behaviors based on context. Peter is polymorphic .
POLY MORPHISM Run Time / Dynamic P olymorphism Compile Time / Static Polymorphism Method Overloading Constructor Overloading Method Hiding Method Overriding Example: Example: CLASSIFICATIONS OF POLYMORPHISM
COMPILE TYPE POLYMORPHISM => METHOD OVERLOADING Compile-time or static polymorphism : Determined at compile time. Implemented through method overloading and function templates. No runtime overhead for method resolution. Enhances code efficiency. Errors detected early during compilation.
Compile-time polymorphism selects the appropriate method or function based on their signatures during compilation . IIUSTRATION => METHOD OVERLOADING
If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java . RUN TIME POLYMORPHISM => METHOD OVERRIDING
Runtime polymorphism : Determined at runtime. Enabled by inheritance and virtual functions. Late binding. Uses virtual function tables ( vtables ) in some languages. Enhances code flexibility and extensibility.
RUN TYPE POLYMORPHISM => METHOD OVERRIDING The method must have the same name as in the parent class The method must have the same parameter as in the parent class . There must be an IS-A relationship (inheritance). Rules for Java Method Overriding
ADVANTAGES OF POLYMORPHISM Code Reusability Polymorphism enables the reuse of code across different parts of your program by allowing objects of different classes to be treated interchangeably through a common interface or superclass. Ease of Maintenance By using polymorphism, you can make changes to the behavior of your program by modifying the implementations of methods in subclasses or implementing new interfaces, without needing to modify the calling code .
Polymorphism facilitates adding new functionality to your application by extending existing classes or implementing new interfaces, without impacting existing code that relies on polymorphic behavior. Enhanced Extensibility Flexibility in Design With polymorphism, you can design your classes and methods to be more flexible and adaptable to changes, as you can substitute objects of different classes that implement the same interface or inherit from the same superclass.
Q/A SESSION I cannot teach anybody anything. I can only make them think, make them inspire to ask question. - Socrates
That’s all. Thank you for your time and attention. We appreciate it!