Blueprint Based Objects
Learn how to define blueprints that construct consistent objects in BornomalaScript.
Blueprint Based Objects
A blueprint defines the structure and initial behavior for objects of the same kind.
Instead of creating each object from scratch, you define the pattern once and then build new objects from it.
Why Blueprints Matter
Blueprints help you:
- create consistent objects
- reuse structure
- reduce repeated setup code
- keep object creation organized
Basic Example
A blueprint defines the structure and initial behavior:
blueprint Car {
Car(nam, rong) {
ei.nam = nam
ei.rong = rong
}
dekhao() {
lekho("Car nam: ${ei.nam}, rong: ${ei.rong}")
}
updateNam(NotunNam) {
ei.nam = NotunNam
}
updateColor(notunRong) {
ei.rong = notunRong
}
}
dhoro amarCar = notun Car("Ferrari", "lal")
amarCar.dekhao()
amarCar.updateNam("Lamborgini")
amarCar.updateColor("kalo")
amarCar.dekhao()
How It Works
The blueprint defines:
- a constructor that sets initial values
- a method to display the object
- methods to update the object later
When you create a new car, you pass the values you want the object to start with.
Step-by-Step Breakdown
- Define the blueprint
- Add the constructor
- Store the initial values in the object
- Add methods for behavior and updates
- Create a new object from the blueprint
- Call the methods on that object
Why This Example Matters
Blueprints are a useful pattern when you need many objects with the same structure.
For example:
- cars
- students
- books
- products
Each one can share the same pattern but hold different values.
Common Mistakes
Beginners often make these mistakes:
- forgetting to use the blueprint constructor
- confusing object values with blueprint defaults
- not understanding that each object gets its own data
- changing the wrong property name
Try These Variations
Try creating blueprints for:
- A student
- A product
- A device
Add a constructor and one display method.
Quick Checklist
Before moving on, make sure you can:
- explain what a blueprint does
- create a new object from it
- update values using methods
- understand why blueprints help with repeated objects
If yes, you understand the basics of blueprint-based objects.