๐ Day 2 - Real-World Examples of OOP Concepts: Understanding Abstraction and Encapsulation ๐ฅ๐ฉโ๐ป

Table of contents
- ๐ What is Programming Language Evolution?
- 1. Machine Language (Binary: 0s and 1s)
- 2. Assembly Language
- 3. Procedural Programming (Structured Programming)
- ๐ What is Object-Oriented Programming (OOP)?
- ๐ Code-Based Abstraction: Abstract Class
- ๐ Pillars of Object-Oriented Programming: โ 2 ) Encapsulation

NOTE: - My 8-week System Design journey with Coder Army. I'm journaling each day to capture what I learn, reflect on it, and share it with my network to help others who are new to system design.
๐ What is Programming Language Evolution?
Programming language evolution refers to how software languages have developed over timeโfrom machine-level binary codes to modern object-oriented structuresโto better model real-world problems, improve developer productivity, and reduce errors.
(Hindi: Programming language evolution ka matlab hai software bhashao ka vikas, jismein machine level binary code se lekar modern object-oriented languages tak ka safar shamil hai. Isse developers ko complex problems solve karne mein aasani hoti hai aur error bhi kam hoti hai.)
1. Machine Language (Binary: 0s and 1s)
In the earliest days, programmers wrote code using binary digits (0 and 1). These were direct CPU instructions.
๐ Example:
0100101
1100101
๐ Drawbacks:
Extremely error-prone โ One wrong bit and the whole program breaks.
(Hindi: Bahut zyada galti hone ki sambhavana โ ek bit ki galti se pura program kharab ho jata tha.)Tedious to write and maintain.
(Hindi: Likhna aur maintain karna mushkil tha.)No abstraction โ Programmer had to manage every single detail.
(Hindi: Koi abstraction nahi thi โ har chhoti detail manually manage karni padti thi.)
๐ Real-Life Analogy:
Itโs like trying to build a house by only using Morse code instructions without any blueprint.
2. Assembly Language
To simplify things, Assembly Language introduced mnemonics (like MOV, ADD, SUB). These were symbolic instructions that directly mapped to machine language.
๐ Example:
MOV A, 61h
๐ Drawbacks:
Still hardware-dependent โ Changing CPU meant rewriting code.
(Hindi: Ab bhi hardware ke upar depend tha โ CPU badalne par code bhi badalna padta tha.)No structured logic like loops or functions.
(Hindi: Loop ya function jaise structure nahi the.)Poor scalability โ Only worked well for small systems.
(Hindi: Sirf chhote system ke liye theek tha โ large systems mein fail.)
๐ Real-Life Analogy:
Imagine giving cooking instructions in your native language but still needing to tell every little actionโno shortcuts or reusable steps.
3. Procedural Programming (Structured Programming)
As systems grew complex, languages like C introduced structured programming: loops, functions, and conditional statements like if-else, switch.
๐ Example:
void cook() {
boilWater();
addRice();
stir();
}
๐ Features Introduced:
Functions for code reuse
(Hindi: Code ko baar-baar use karne ke liye functions aaye.)
Control Structures: if-else, loops
(Hindi: Decision making aur repetition ke liye control structures aaye jaise if-else, for loop.)Better readability and debugging
(Hindi: Code padhna aur debug karna aasaan hua.)
๐ Limitations:
Poor real-world modeling: Couldnโt directly model entities like โUser,โ โDriver,โ or โPayment.โ
(Hindi: Complex systems jaise ride-booking app mein user, driver jaise real-world objects ko model karna mushkil tha.)No data security โ Everything was globally visible.
(Hindi: Data security ka issue tha โ sab kuch globally accessible tha.)
๐ Real-Life Analogy:
You can cook multiple recipes using a recipe book (functions), but you still have no way to store who is the chef or assign kitchen roles (objects, permissions).
๐ Why It Matters?
Understanding these older paradigms helps us appreciate the Object-Oriented Programming (OOPs) approach that solves many of these issues โ like abstraction, encapsulation, and modularity โ enabling us to build scalable, maintainable software.
(Hindi: In purani programming styles ko samajhne se humein pata chalta hai ki Object-Oriented Programming kyun zaruri hai โ yeh problems ka better solution deti hai.)
๐ What is Object-Oriented Programming (OOP)?
Object-Oriented Programming (OOP) is a paradigm that allows us to build software by modeling it after real-world entities โ things that have characteristics (attributes) and can perform actions (behaviors).
(Hindi: OOP ek aisa tarika hai jisme hum real-world ki cheezon jaise objects ko code mein model karte hain. Jaise kisi cheez ke attributes (characteristics) aur behavior (karya) hote hain, waise hi hamare code mein bhi honge.)
1. Why OOP?
As software systems grew complex (think Uber, Ola, Zomato), we needed a way to map real-world problems into code more naturally and securely.
OOP allows us to:
๐ฅ Model real-world entities as objects (e.g., User, Car, Ride)
๐ Secure data via encapsulation (only allow safe access)
โป Reuse code using inheritance and interfaces
๐ Build scalable systems with loosely-coupled modules
(Hindi: OOPs se hum real-world ke complex problems ko code mein asani se model kar sakte hain. Data ko secure kar sakte hain, aur code ko reuse kar sakte hain.)
๐ Core Ideology of OOP:
โProgram the way the real world works โ with objects that interact.โ
(Hindi: Programming ko is tarah karo jaise real world mein objects interact karte hain.)
Example: Car and Owner ๐๐ง
Letโs model a simple real-world interaction: A person owns and drives a car.
๐ Real-world Thought:
Object 1: Car
Characteristics (Attributes): brand, model, isEngineOn
Behaviors (Methods): start(), stop(), gearShift(), accelerate(), brake()
Object 2: Owner
Characteristics: name
Behavior: drive()
(Hindi: Car ek object hai jismein kuch features hain jaise brand, model, aur kuch functions hain jaise start karna, brake lagana. Waise hi owner ek object hai jo car ko use karta hai.)
๐ง OOP Code Representation:
๐น Car Class:
public class Car {
String brand;
String model;
boolean isEngineOn;
public void start() {
isEngineOn = true;
System.out.println("Car started");
}
public void stop() {
isEngineOn = false;
System.out.println("Car stopped");
}
public void gearShift() {
System.out.println("Gear shifted");
}
public void accelerate() {
System.out.println("Accelerating...");
}
}
๐น Owner Class:
public class Owner {
String name;
Car car;
public void drive() {
System.out.println(name + " is driving the car.");
car.start();
car.gearShift();
car.accelerate();
}
}
๐น Main Function:
public class Main {
public static void main(String[] args) {
Car myCar = new Car();
myCar.brand = "Toyota";
myCar.model = "Corolla";
Owner owner = new Owner();
owner.name = "Alice";
owner.car = myCar;
owner.drive();
}
}
(Hindi: Yahaan Owner aur Car ke objects ek dusre se interact kar rahe hain. Owner apni car ko drive kar raha hai, aur car ke methods jaise start(), gearShift() call ho rahe hain.)
2. Modeling Real-World Entities in Code
Letโs break it down even more:
Object: A real-world thing (Car, User, Ride)
(Hindi: Object matlab ek vastu jiska koi role hai, jaise car.)Class: Blueprint of object (defines properties & behaviors)
(Hindi: Class ek design hai jiske base par object banta hai.)Instance: Actual object created using the class
(Hindi: Instance class ka actual object hai jo memory mein create hota hai.)Example:
class Car โ Blueprint
Car myCar = new Car(); โ Instance of Car
๐ Summary:
OOP makes code look and behave like the real world.
Every object has characteristics (fields) and behavior (methods).
Objects can interact with each other just like in the real world.
This interaction builds modular, maintainable, and scalable systems.
(Hindi: OOP mein hum aise programs banate hain jo real world ki tarah dikhte aur behave karte hain. Objects ke beech interaction ke through hum complex systems ko asani se model kar sakte hain.)
๐ Pillars of Object-Oriented Programming: โ 1) Abstraction
- Abstraction hides unnecessary implementation details and shows only the relevant information needed to interact with an object. Or Abstraction โ "Show only whatโs necessary, hide everything else!"
(Hindi: Abstraction mein kisi object ke andar ka kaam kaise ho raha hai yeh nahi dikhaya jata, sirf itna dikhaya jata hai jitna user ko chahiye. or Abstraction ka matlab hota hai โ "Sirf zaroori cheezein dikhana, baaki sab chhupa lena.")
Real-World Analogies
1 ) You can start the car, press the pedals, and turn the wheel.
What you don't need to know:
โ How the engine combustion works
โ How fuel reaches the engine
โ How the gears change internally
(Hindi: Aapko yeh jaanna zaroori nahi hai ki car ka engine internally kaise kaam karta hai, aapko sirf car chalani aani chahiye.)
2 ) Using a Laptop
You use apps, click buttons, browse the internetโฆ
But:
โ You donโt care how the OS schedules tasks
โ How the RAM and processor manage memory
Thatโs abstraction โ the complex logic is hidden from the user.
(Hindi: Hum laptop chalate hain, par use banane ka internal process nahi samajhte, yeh hi abstraction hai.)
Programming Level Abstraction
Control Structures like:
๐น if
๐น for
๐น while
They are high-level instructions.
The compiler takes care of converting these into machine-level instructions!
(Hindi: if-else, loops jaise keywords high-level abstraction provide karte hain. Compiler inhe machine code mein convert karta hai.)
๐ Code-Based Abstraction: Abstract Class
public abstract class Car {
// Abstract methods - no implementation here
public abstract void startEngine();
public abstract void shiftGear(int newGear);
public abstract void accelerate();
public abstract void brake();
}
- This is an abstract class.
(Hindi: Yeh ek abstract class hai jismein sirf method ke naam hain, implementation nahi.)
๐ Key Points in Java:
Java uses the
abstract
keyword for both abstract classes and methods.Abstract methods do not have a body (
{}
), just a signature.You cannot instantiate an abstract class directly.
Any class that extends
Car
must implement all its abstract methods, unless that class is also declared abstract.
๐ Concert Subclass Example
// Concrete implementation of Car
public class SportsCar extends Car {
public void startEngine() {
System.out.println("SportsCar engine started! ๐๏ธ");
}
public void shiftGear(int newGear) {
System.out.println("Gear shifted to " + newGear);
}
public void accelerate() {
System.out.println("SportsCar accelerating! ๐ฅ");
}
public void brake() {
System.out.println("Applying brakes! ๐");
}
}
public class Main {
public static void main(String[] args) {
Car myCar = new SportsCar();
myCar.startEngine();
myCar.shiftGear(2);
myCar.accelerate();
myCar.brake();
}
}
๐ Benefits of Abstraction
Simplified Interfaces
Clients focus on what an object does, not how it does it.
(Hindi: User ko sirf object ka kaam dikhai deta hai, andar ki complexity nahi.)Ease of Maintenance
You can change the internal code without affecting the client code.
(Hindi: Agar andar ka code badla bhi jaaye to client side pe koi asar nahi padta.)Code Reuse
You can reuse the same interface for different classes โ e.g., SUV, Sedan, ElectricCar.
(Hindi: Aap same interface se alag-alag types ke cars bana sakte ho.)Reduced Complexity
System becomes modular and easy to manage.
(Hindi: System simple aur manageable ban jata hai.)
๐ Pillars of Object-Oriented Programming: โ 2 ) Encapsulation
Encapsulation means wrapping data (state) and methods (behavior) into a single unit called a class and restricting direct access to some of the object's components.
Encapsulation is like a protective capsule for your data! It bundles data (variables) and behaviors (functions) together, and controls how the outside world can access them.
(Hindi: Encapsulation ek capsule ki tarah hota hai jo data aur us par hone wale operations ko ek sath bandh kar rakhta hai. Ye ensure karta hai ki sensitive data ko bahar se direct access na mile.)
๐ Two Facets of Encapsulation
1๏ธโฃ Logical Grouping
- Data + Functions = One cohesive unit
๐ Example:
Car class will contain:
engineOn (bool)
currentSpeed (int)
accelerate(), shiftGear(), brake() functions
(Hindi: Logical grouping ka matlab hai related data aur functions ko ek hi jagah rakhna, jaise Car class ke andar sab kuch car se related milega.)
2๏ธโฃ Data Security
Prevent direct access to sensitive data fields.
Example: You can view the carโs mileage (odometer) but canโt reset it.
(Hindi: Data security ka matlab hai important fields ko protect karna. Jaise ki car ka odometer sirf read ho sakta hai, set nahi.)
๐ Real-World Analogies
๐ Medicine Capsule:
Data = Medicine inside
Wrapper = Protection
You can take it without knowing the inner chemicals!
(Hindi: Capsule mein dawai aur uski safety ek sath hoti hai. Aap usko lete ho bina andar ke ingredients jaane.)
๐ Car Odometer:
You can read kilometers driven.
You canโt directly set it to 0.
(Hindi: Aap car ka odometer dekh sakte ho, lekin usse reset nahi kar sakte.)
public class Car {
private int speed;
private int odometer;
public void setSpeed(int s) {
if (s > 0) {
speed = s;
}
}
public int getSpeed() {
return speed;
}
public int getOdometer() {
return odometer;
}
public void drive(int distance) {
if (distance > 0) {
odometer += distance;
}
}
}
๐ Access Modifiers in Java
๐ public โ Accessible from anywhere
๐ private โ Only accessible inside the class
๐ protected โ Accessible in the class and its child classes
(Hindi: Ye access modifiers define karte hain ki kaunsa data kahaan se access ho sakta hai.)
๐ Getters & Setters: Controlled Access
Getters allow safe read access.
Setters allow controlled modifications with validations.
Allow controlled mutation with checks, rather then exposing fileds blindly
(Hindi: Getter aur Setter functions se aap data ko secure tarike se access aur modify kar sakte ho, bina direct access diye.)
๐ Benefits of Encapsulation
Robustness:
Protects data from accidental or intentional misuse.Maintainability:
You can change internal code without affecting outside users.Clear Contracts:
Users interact via defined functions only.Modularity:
Helps organize code better and makes testing easier.
๐ Difference: Data Hiding vs Data Security
Data Security:
Important info agar leak ho gaya toh threat ban sakta hai.Data Hiding:
Agar kuch data hide bhi ho gaya aur kisi ne dekh liya โ koi dikkat nahi.
(Hindi: Data hiding aur security mein farq hai. Security mein data leak se danger ho sakta hai. Hiding mein aisa zaroori nahi.)
Day 2 Completed โ System Design
NOTE : - A big thanks to my mentors Rohit Negi Sir and Aditya Sir for launching this amazing 8-week course absolutely free on YouTube via CoderArmy9 :- https://www.youtube.com/@CoderArmy9 . ๐
๐ Share this blog with your connections! Letโs keep learning, growing, and supporting one another on this journey. ๐
โ๏ธ Payal Kumari ๐ฉโ๐ป
Jai Hind ๐ฎ๐ณ | #CoderArmy #LearningInPublic #SystemDesign #TechForAll #MentorshipMatters #8weeksLLdChallenge #LowLevelDesign #Code #LLD #OOP ๐ฉโ๐ป
Subscribe to my newsletter
Read articles from Payal Kumari directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Payal Kumari
Payal Kumari
I'm a passionate full-stack developer with a strong foundation in the MERN stackโbuilding and maintaining scalable web applications using React.js, Node.js, and Next.js. My journey in open source began with Hacktoberfest 2023, where I made four impactful pull requests that sparked a love for collaborative coding, global learning, and open knowledge sharing. Since then, Iโve contributed to and mentored projects in top open source programs like GSSoCโ24, SSOCโ24, and C4GTโ24. As a Google Gen AI Exchange Hackathon โ24 Finalist and Googleโs Women Techmakers (WTM) Ambassador, Iโve been privileged to support diverse communities in building meaningful tech solutions. My work as a Top 50 Mentor for GSSoC โ24 reflects my commitment to nurturing new talent in tech. Beyond development, I serve as a Student Career Guide, Profile Building Expert & Evangelist at Topmate.io, where I conduct workshops, guide students through resume building and career strategy, and help mentees navigate open source and tech careers. Recognized among the Top 5% of mentors and featured on โTopmate Discover,โ I take pride in making mentorship accessible and impactful. My technical voice has also been acknowledged by LinkedIn, where Iโve earned the Top Voice badge seven times in domains like web development, programming, and software engineering. In addition, I hold LinkedIn Golden Badges for Research Skills, Interpersonal Skills, Critical Thinking, and Teamworkโsignaling a well-rounded approach to both individual contribution and team collaboration. Graduating with an MCA from Chandigarh University in 2023, Iโve continued to fuel my curiosity by writing technical articles and sharing practical MERN stack insights across platforms. Whether itโs building polished UIs, optimizing backend performance, or guiding a mentee through their first pull request, Iโm driven by the power of community and continuous learning. Letโs connect! I'm open to collaborations, mentorship, or building something impactful together. Reach out to me at kumaripayal7488@gmail.com or visit my profile on Topmate.io.