OOP · Building Blocks of OOP
What is a Class?
Each class can be tested independently.
As the business grows, new features such as Wishlist, Coupons, Reviews, and Gift Cards can be added by creating new classes. Existing functionality remains unchanged, making the application easier to expand.
🧪 Testable Each class can be tested independently. For example, developers can test the User, Cart, and Payment classes separately. This makes it easier to identify bugs and ensures each module works correctly before integration.
🔒 Secure Sensitive information such as passwords, account numbers, and payment details should not be accessible from every part of the application. OOP helps protect this data by allowing controlled access through its classes, improving the overall security of the software.
Introduction
A class is a blueprint or template used to create objects. It defines the properties (data) and behaviors (methods) that every object of that class will have. Definition: A class is a user-defined blueprint that groups related data and methods into a single unit. Why Do We Need a Class? Imagine building 100 student records.
Without a class:
- Create separate variables for each student
- Repeat the same code multiple times
- Difficult to maintain
With a class:
- Define the structure once
- Create unlimited student objects
- Easy to manage and reuse

Real-Life Examples
- 🏠 House Blueprint → Houses
- 🚗 Car Design → Cars
- 🏦 Bank Account Template → Customer Accounts
- 🎓 Student Class → Student Objects

A class is a blueprint: it declares what every object of that type will have and do.
// Blueprint for cars — no car exists yet, just the design
public class Car {
String model; // attribute
int speed; // attribute
void accelerate(int by) { // behavior
speed += by;
}
void brake() {
speed = 0;
}
}