0% found this document useful (0 votes)
2 views1 page

Pattern Study Inheritance

Inheritance is a fundamental concept in Object-Oriented Programming that enables a subclass to inherit attributes and methods from a superclass. It offers benefits such as code reusability, extensibility, and method overriding. The document also advises using composition over inheritance when only partial functionality is needed, emphasizing the importance of a clear 'is-a' relationship.

Uploaded by

ritik sarathe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Pattern Study Inheritance

Inheritance is a fundamental concept in Object-Oriented Programming that enables a subclass to inherit attributes and methods from a superclass. It offers benefits such as code reusability, extensibility, and method overriding. The document also advises using composition over inheritance when only partial functionality is needed, emphasizing the importance of a clear 'is-a' relationship.

Uploaded by

ritik sarathe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INHERITANCE

Pattern Study Series: Technical Overview

Overview

Inheritance is a core pillar of Object-Oriented Programming (OOP). It allows a new class


(Subclass/Child) to inherit the attributes and methods of an existing class (Superclass/
Parent).

Primary Benefits

• Code Reusability: Define common logic once in the parent class.


• Extensibility: Child classes can add their own unique features.
• Method Overriding: Child classes can provide a specific implementation of a method
defined in the parent.

class Animal:
def speak(self):
print("Animal makes a sound")

class Dog(Animal): # Inherits from Animal


def speak(self): # Overriding
print("Bark!")

my_dog = Dog()
my_dog.speak() # Output: Bark!

Design Principle: Favor "Composition over Inheritance" if you only need parts of a
class's functionality. Use inheritance when there is a clear "is-a" relationship (e.g., a
Dog is an Animal).

Programming Concepts & Patterns Reference Guide • 2024

You might also like