Object Oriented Programming - Inheritance

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

OBJECT ORIENTED

PROGRAMMING:

INHERITANCE
Dominique, Adron and Taniya
WHOA!
“I might not think that programmers are
artists, but programming is an extremely
creative profession. It’s logic-based
creativity.” ~ John Romero
TABLE OF CONTENTS

0 INTRODUCTION
What is Inheritance in OOP?
0 EXAMPLE
Illustration of how
1 2 inheritance is used

0 ADVANTAGES 0 DISADVANTAGE
Pros S
Cons
3 4
01
INTRODUCTIO
N
What is Inheritance?
DEFINING THE
CONCEPT
Inheritance is a fundamental concept in object-oriented programming
(OOP). It allows a new class (called the "subclass" or "child class") to inherit
attributes and methods from an existing class (called the "superclass" or
"parent class"). The subclass can then extend or modify the behavior of the
superclass by adding its own attributes and methods or by overriding
existing ones.
EXAMPLES
02
An example to illustrate the concept
TYPES OF INHERITANCE

0 SINGLE
In single inheritance, a subclass (or
0 MULTIPLE
In multiple inheritance, a subclass

0 child class) inherits from only one


superclass (or parent class). 0 inherits from multiple
superclasses.

0 MULTILEVEL
In multilevel inheritance, a
0 HIERARCHY
In hierarchical inheritance,

0 subclass inherits from another


subclass. 0 multiple subclasses inherit from a
single superclass.

Consider a scenario where we have two classes:
Animal (the superclass) and Dog (the subclass).
The Dog class inherits features from the Animal
class.

These features include: eating, sleeping, drinking


The concept of inheritance establishes
An “is-a” relationship.

A CAR AN A DOG A
IS A VEHICLE ORANGE
IS A FRUIT IS AN ANIMAL SURGEON
IS A DOCTOR
03
ADVANTAGES
Pros of inheritance in OOP
ADVANTAGES
Inheritance promotes code reuse by allowing subclasses
to inherit attributes and methods from their superclasses.
Code Reusability This reduces redundancy and improves maintainability, as
common functionality only needs to be implemented
once in the superclass.

Inheritance facilitates modularity by organizing classes


Enhanced into a hierarchical structure. Subclasses can specialize
behavior while inheriting common characteristics from
Modularity their superclasses. This makes the codebase easier to
understand and manage.

When changes are required, inheritance allows


Ease of modifications to be made at the superclass level, affecting
all subclasses that inherit from it. This simplifies
Maintenance maintenance and ensures consistency across related
classes.
DISADVANTAG
04 ES
Cons of inheritance in OOP
DISADVANTAGES

Hierarchical inheritance can lead to complex class


Complexity hierarchies.

Once you’ve established a class structure, altering it (e.g.,


adding new features or changing relationships) can be
Limited Flexibility tricky. Changes may inadvertently affect existing code,
leading to unintended consequences.

Increased Risk of Errors introduced in the superclass can propagate down


the hierarchy.
Bugs
A PICTURE IS
WORTH A
THOUSAND
WORDS
REFERENCES
● C++ multiple, multilevel and hierarchical inheritance. (n.d.). Programiz: Learn to
Code for Free.
https://www.programiz.com/cpp-programming/multilevel-multiple-inheritance
● Codecademy Team. (2023, July 11). What is inheritance in object-oriented
programming? Codecademy Blog.
https://www.codecademy.com/resources/blog/what-is-inheritance/
● Inheritance in Java. (2023, September 13). GeeksforGeeks.
https://www.geeksforgeeks.org/inheritance-in-java/
● PHP OOP inheritance. (n.d.). W3Schools Online Web Tutorials.
https://www.w3schools.com/PHP/php_oop_inheritance.asp
● Yadav, N. (2021, April 13). Advantages and disadvantages of inheritance in Java.
The Java Programmer.
https://www.thejavaprogrammer.com/advantages-and-disadvantages-of-inheritan
ce-in-java/
THANKS
!
Credits: This presentation template was created by
Slidesgo, including icons by Flaticon, and
infographics & images by Freepik
Please keep this slide for attribution

You might also like