Inheritance

Learn how inheritance lets one object reuse or extend behavior from another in BornomalaScript.

Inheritance

Inheritance lets one object or blueprint reuse behavior from another.

That is useful when two things share the same core behavior but one of them needs extra features.

Why Inheritance Matters

Inheritance helps you avoid repeating code.

Instead of rewriting the same behavior again and again, you can define a base version and extend it where needed.

Simple Example

Imagine a base object for a person and a more specific object for a student.

The student can reuse the person’s common data and add school-specific details.

Conceptual Example

dhoro Person = {
	nam: "",
	boltePare: kaj() {
		lekho("Ami ekjon manush")
	}
}

dhoro Student = Person
Student.className = ""

This is a simplified example to show the idea of reusing behavior.

How It Works

Inheritance usually gives you:

  • a parent type
  • a child type
  • shared behavior in the parent
  • extra behavior in the child

That means you can build more specific things without starting from zero each time.

Step-by-Step Breakdown

  1. Create a base object or blueprint
  2. Put common behavior there
  3. Create a more specific version
  4. Add or change only the behavior that is different

Common Mistakes

Beginners often make these mistakes:

  • using inheritance when simple composition would be better
  • adding too much into the base type
  • forgetting that the child should only extend what it needs

Practice Task

Try designing inheritance for:

  1. Vehicle and Car
  2. Person and Teacher
  3. Device and Phone

Think about what should stay shared and what should be unique.

Quick Checklist

Before moving on, make sure you can:

  • explain why inheritance is useful
  • identify a shared parent concept
  • describe how a child type can extend it

If yes, you are ready for polymorphism.