Skip to main content

INHERITANCE vs POLYMORPHISM

Distinguishing Inheritance and Polymorphism in UML Class Diagrams / OOP

1. CORE DIFFERENCE

ASPECT INHERITANCE POLYMORPHISM
Basic Meaning A class inherits characteristics from another class. The same operation/interface can behave differently depending on the object.
Main Question "What does this class inherit from?" "How can the same operation have different behaviors?"
Relationship IS-A relationship. ONE INTERFACE → MANY BEHAVIORS
UML Representation Generalization arrow with a hollow triangle. Usually represented through overridden operations in subclasses.
Primary Mechanism Parent/Superclass → Child/Subclass. Method overriding / dynamic dispatch.
Main Purpose Reuse and specialization. Flexibility and interchangeable objects.
Example Car inherits from Vehicle. Car.move() and Motorcycle.move() behave differently.

2. INHERITANCE

Inheritance is a structural relationship between classes. A subclass obtains attributes and/or operations from a superclass, and can add or specialize them.
┌─────────────────┐ │ Vehicle │ ├─────────────────┤ │ - brand │ │ - speed │ ├─────────────────┤ │ + move() │ └────────┬────────┘ △ │ ┌───────────┴───────────┐ │ │ ┌─────────────────┐ ┌─────────────────┐ │ Car │ │ Motorcycle │ ├─────────────────┤ ├─────────────────┤ │ - numberOfDoors │ │ - engineCC │ └─────────────────┘ └─────────────────┘
UML Generalization:
Car ─────────▷ Vehicle
Motorcycle ───▷ Vehicle

Conceptually: Car IS-A Vehicle.
Motorcycle IS-A Vehicle.

Therefore, inheritance answers:
"What class is this class derived from?"

3. POLYMORPHISM

Polymorphism means that the same operation/interface can produce different behavior depending on the actual object receiving the operation.
Vehicle │ ├── Car │ └── move() → moves on four wheels │ └── Motorcycle └── move() → moves on two wheels

The operation name remains the same:

move()

But its behavior changes according to the object's actual type.

Vehicle v v = Car v.move() → Car's implementation v = Motorcycle v.move() → Motorcycle's implementation

4. THE RELATIONSHIP BETWEEN THEM

INHERITANCE ↓ STRUCTURE / RELATIONSHIP ↓ "Dog is an Animal" ↓ common interface ↓ POLYMORPHISM ↓ BEHAVIOR / SUBSTITUTION ↓ "Animal reference can represent Dog or Cat" ↓ same operation → different implementation
Key Idea:

Inheritance creates the class relationship.
Polymorphism exploits a common interface so different classes can behave differently.

5. SIMPLE REAL-WORLD ANALOGY

ANIMAL │ ┌────────┴────────┐ ▼ ▼ DOG CAT

Inheritance

Dog IS-A Animal
Cat IS-A Animal

Polymorphism

makeSound() Dog.makeSound() → "Woof!" Cat.makeSound() → "Meow!"
The same message makeSound() produces different behavior.

6. UML CLASS-DIAGRAM VIEW

┌─────────────────────┐ │ Animal │ ├─────────────────────┤ │ + name │ ├─────────────────────┤ │ + makeSound() │ └──────────┬──────────┘ △ ┌──────────┴──────────┐ │ │ ┌─────────────────┐ ┌─────────────────┐ │ Dog │ │ Cat │ ├─────────────────┤ ├─────────────────┤ │ + makeSound() │ │ + makeSound() │ └─────────────────┘ └─────────────────┘ │ │ ▼ ▼ "Woof!" "Meow!"
Inheritance:
Dog ─────▷ Animal
Cat ─────▷ Animal

Polymorphism:
makeSound() → Dog behavior / Cat behavior

7. THE MOST IMPORTANT DISTINCTION

CONCEPT FOCUS QUESTION
Inheritance Structure / Class Relationship "What does this class inherit?"
Polymorphism Behavior / Substitution "What behavior occurs when this operation is invoked?"

FINAL SUMMARY

INHERITANCE = CLASS RELATIONSHIP

A subclass derives from a superclass and inherits/reuses its characteristics.


POLYMORPHISM = BEHAVIORAL VARIABILITY THROUGH A COMMON INTERFACE

Different objects can respond differently to the same operation/interface.

INHERITANCE → WHAT A CLASS IS / RECEIVES
POLYMORPHISM → HOW AN OBJECT CAN BEHAVE

Comments

Popular posts from this blog

Utk yg mo Bantu2 Keuangan saya
..monggo ke Bank Central Asia BCA 5520166779 a.n. Andreas Tparlaungan Manurung (Indonesia)


For those who would like to help support my finances
..please feel free to send it to Bank Central Asia (BCA) account number 5520166779 under the name Andreas Tparlaungan Manurung (Indonesia)

ANDREAS TOMMY PARLAUNGAN MANURUNG SHARED POOLING ACCOUNT MY ANDROID APKs PAGE please download here! REFRESH PAGE aka CHECK LATEST UPDATE! DOWNLOAD "SHOWING" POOL OF MY ANDROID-APK(s) aka APK CONTAINING LIST OF ALL MY ANDROID-APK(s) APP CLICK HERE FOR ALWAYS BEING UPDATED FOR MY LATEST APK! CONTOH HASIL "PROGRAM" App: Prompts' Guide aka TEMPLATE-HELPERs click here to download! Youtube and Instagram EMBEDded to Blogger/Blogspot.com SOURCE CODE Click this box to download 📥 TikTok EMBEDded to Blogger/Blogspot.com SOURCE CODE Input: BrowserLINK (mandatory) Click this box to download SHORTCUT-APPs note :  "precise" click to download R8: ronin1985.blogspot.com R2M: ronin-manu.blogspot.com Helping Download(ing) OnlineVIDEO! ...

[ERROR BUG]
ChatGPT+Gemini: TikTok → Blogger Embed Converter using Cloudflare/Online Server

🔄 Refresh Page ERROR BUG: The connection is blocked because it was initiated by a public page to connect to devices or servers on your local network. Planning: Revise Program CODE Code USING Javascript/Online Server Code NOT USING Javascript Sample Working Code aka Already Repaired! Temporary Solution is by Asking AI Assistant to do REPAIR CODE of (Not yet Repaired) Current Conversion Program Code-Output TikTok Archive – Embedded Preview TikTok Embed ▶ View this video on TikTok ⚠️ DISCLAIMER: INPUT URL LIMITATION This program is currently restricted to processing Full Browser URLs only. It does not support TikTok’s mobile "short-link" format (e.g., vt.tiktok.com ). Required Action: Users must open the video in a web browser and copy the expanded URL from the address bar before pasting it into this program. URL Conversion Example ❌ UNSUPPORTED: https://vt.tiktok.com/ZSaXoFyov/ ✅ REQ...

REPOST: Studying WATER PUMP by ROMAN ENGINEERING

*^ Ini yg Asli Gan! Mekanisme pada Concrete Pump: Kok ky Sistem Mekanik Romawi ya?! Tapi malah bisa HANYA pake PER aka bukan "MATA BOR look a like" Mekanisme Drill yg Cost Pembuatan bikin REPOT aka harus Tool SUPER Khusus Dari Material Besi yg digunakan terlihat langsung secara kasat mata Jauh Lebih Banyak drpd Per Biasa seperti yg ditunjukkan pd Video Alternatif dgn Penggunaan PER Video dr Instagram: Source: YouTube Rome's drainage machines #history #romanempire #engineering