Inheritance
Pronunciationin-HAIR-ih-tans
Definition
When a class reuses the properties and methods of another class and can add or change some of them.
Where you hear it
Object-oriented design and interviews ("composition over inheritance").
Examples
AdminUserinherits fromUser.Deep inheritance chains are hard to maintain.
The AdminUser class inherits the login method from User and adds its own permissions.
Common mistake
Using inheritance just to share code. If the relationship is not "is a", prefer composition.
Don't confuse with
Inheritance defines an "is-a" relationship where a subclass reuses parent behavior, while composition defines a "has-a" relationship by combining independent objects.
Say it at work
- In a meeting or chat
Let us use inheritance here so that the admin class can reuse the common user methods.
- In an email or ticket
Please refactor this deeply nested inheritance tree into smaller components to improve maintainability.
Keep exploring
More in Programming Fundamentals