OOP Mini Project
In this lesson, we apply everything you have learned about Object-Oriented Programming (OOP) in JavaScript.
This lesson focuses on practice, not introducing new theory. You will see how OOP concepts work together in a small but realistic project.
Project Objective
The goal of this mini project is to:
- Apply OOP concepts in real code
- Use classes and objects correctly
- Understand inheritance and method overriding
- Write clean, readable JavaScript
This mirrors how JavaScript is written in real applications.
Project Scenario
We will build a simple User System.
Each user:
- Has a name
- Has a role
- Can describe themselves
We will model this using classes.
Step 1: Base Class
We start with a base class that represents a generic user.
class User {
constructor(name) {
this.name = name;
}
introduce() {
return `Hi, I am ${this.name}`;
}
}
This class defines shared behavior for all users.
Step 2: Child Class (Inheritance)
Now we extend the base class to create a more specific user type.
class Developer extends User {
constructor(name, language) {
super(name);
this.language = language;
}
introduce() {
return `Hi, I am ${this.name} and I write ${this.language}`;
}
}
Here we used:
- Inheritance using
extends super()to access the parent class- Method overriding
Step 3: Creating Objects
Now we create objects (instances) from our classes.
const dev1 = new Developer("Alex", "JavaScript");
const dev2 = new Developer("Sara", "Python");
console.log(dev1.introduce());
console.log(dev2.introduce());
Each object:
- Shares common behavior
- Has its own data
- Uses the same class definition
Concepts Practiced
- Classes
- Objects
- Inheritance
- Encapsulation
- Method overriding
These are core concepts used in real-world JavaScript projects.
Mini Tasks for Practice
Try extending this project:
- Add another role (Designer, Tester, Manager)
- Add a method to change roles
- Store users in an array and loop through them
These tasks help solidify OOP understanding.
Important Note
This lesson focuses only on OOP concepts.
We intentionally do not include APIs, JSON, or async behavior here. Those topics are covered in the upcoming lessons:
- JSON Basics
- HTTP Methods
- Fetch API
- Async API Integration
Keeping concepts separated makes learning easier.
What Comes Next?
Now that you are comfortable with OOP, the next step is working with data formats and external systems.
In the next lesson, we will start with JSON Basics.