Computational Thinking & Object-Oriented Design
গণনা চিন্তা ও অবজেক্ট-অরিয়েন্টেড ডিজাইন
1. Think Before You Type
Before any syntax, great Java programs start in the head. Computational thinking is the habit of breaking a messy real-world problem into pieces a computer can handle — decomposition, abstraction, pattern recognition, and algorithm design. Object-Oriented Design (OOD) is the Java-flavoured way of doing that: you model the world as objects that carry state and respond to messages.
This module gives you the mental model you will use for the next 49 lectures — and the rest of your Java career.
2. The Four Pillars of Computational Thinking
Jeannette Wing's classic framing — four skills every programmer uses daily:
🧩 Decomposition (বিভাজন)
Break a big problem into small, self-contained sub-problems. "Build a bKash clone" becomes: user, wallet, transaction, ledger.
🎨 Abstraction (বিমূর্তকরণ)
Keep what matters, hide what doesn't. A Car for a ride-hailing app needs location and capacity — not tire pressure.
🔁 Pattern Recognition (প্যাটার্ন)
Different problems, same shape. "Sort users by name" and "sort products by price" are the same algorithm — only the comparator changes.
📜 Algorithm Design (অ্যালগরিদম)
Write the exact steps. Steps must be unambiguous, finite, and correct for all inputs — not just the easy ones.
3. From Problem to Design — Nouns & Verbs
A classic OOD trick: read the problem statement, underline nouns — those become classes. Underline verbs — those become methods.
"A student at NSU can borrow a book from the library. Each book has a title and an ISBN. The library keeps track of how many copies are available."
- Nouns: Student, Book, Library → candidate classes.
- Verbs: borrow, keep track → candidate methods.
- Adjectives (title, ISBN, copies): candidate fields.
4. Class vs Instance — The Recipe and the Cake
A class is a blueprint. An instance (object) is a
concrete thing built from that blueprint. A Book class describes what every book
has; new Book(...) creates an actual book in memory.
// Class = blueprint. Instance = real object in memory.
class Book {
String title;
String isbn;
int copies;
Book(String t, String i, int c) {
title = t; isbn = i; copies = c;
}
void describe() {
System.out.println(title + " (" + isbn + ") — " + copies + " copies");
}
}
class Main {
public static void main(String[] args) {
Book b1 = new Book("Effective Java", "978-0134685991", 3);
Book b2 = new Book("Clean Code", "978-0132350884", 5);
b1.describe();
b2.describe();
}
}
5. The Four OOP Pillars — A Preview
You will meet each of these in detail in Phase 3. For now, the shape of the road ahead:
- Encapsulation — hide internal state; expose a safe API.
- Inheritance — reuse a class by extending it (
class Dog extends Animal). - Polymorphism — one interface, many behaviors at runtime.
- Abstraction — describe what a type does, not how.
6. UML — A One-Page Design Language
Before writing code, sketch your classes on paper or a whiteboard. UML (Unified Modeling Language) gives a simple notation — you don't need the full spec, just the class box:
- মানে private, + মানে public। Library-র কাছে একাধিক Book থাকে — তাই "has-a" সম্পর্ক।
7. A Small Real Design — bKash Wallet Sketch
Let's decompose "a simple bKash-style wallet" into classes and run a tiny prototype:
// Nouns: User, Wallet, Transaction — Verbs: deposit, send
class Wallet {
String ownerName;
double balance;
Wallet(String name, double opening) {
ownerName = name; balance = opening;
}
void deposit(double amount) {
balance += amount;
System.out.println(ownerName + " deposited ৳" + amount);
}
boolean sendTo(Wallet other, double amount) {
if (amount > balance) { System.out.println("Not enough balance"); return false; }
balance -= amount;
other.balance += amount;
System.out.println(ownerName + " → " + other.ownerName + " : ৳" + amount);
return true;
}
}
class Main {
public static void main(String[] args) {
Wallet arif = new Wallet("Arif", 500.0);
Wallet nila = new Wallet("Nila", 0.0);
arif.deposit(200);
arif.sendTo(nila, 300);
System.out.println("Arif balance: ৳" + arif.balance);
System.out.println("Nila balance: ৳" + nila.balance);
}
}
৩০ লাইনেরও কম, কিন্তু দুটি object নিজ নিজ balance ধরে রেখে লেনদেন করছে — এটাই OOP-এর শক্তি।
8. Vocabulary (শব্দভাণ্ডার)
| Term | Meaning | বাংলায় |
|---|---|---|
| Class | A blueprint describing fields and behavior. | object তৈরির blueprint। |
| Object / Instance | A concrete value produced from a class. | class থেকে তৈরি বাস্তব object। |
| Field (attribute) | A variable living inside an object. | object-এর ভেতরে থাকা variable। |
| Method | A behavior an object can perform. | object-এর কাজ বা ক্রিয়া। |
| Constructor | Special method that initializes a new object. | নতুন object-এর প্রথম সেটআপ। |
| UML | Unified Modeling Language — visual design notation. | design আঁকার আদর্শ notation। |
| Abstraction | Ignoring irrelevant detail to focus on essentials. | অপ্রয়োজনীয় detail বাদ দিয়ে মূল বিষয়ে মনোযোগ। |
9. Practice Problems
Try each on your own first, then expand the answer.
-
Read the statement "A student at NSU registers for a course taught by a teacher." List the classes, fields, and methods.উপরের বাক্য থেকে class, field এবং method খুঁজে বের করুন।
✨ Show Answer (উত্তর দেখুন)
Classes: Student, Course, Teacher. Fields: Student{id, name}, Course{code, credits}, Teacher{name, department}. Methods: Student.register(Course), Course.addStudent(Student), Teacher.teach(Course).
Class: Student, Course, Teacher। Field: id, name, code, credits, department। Method: register, addStudent, teach।
-
Create a
Studentclass with fieldsnameandcgpa, and a methoddescribe(). Create two students and print them.Student class তৈরি করে দুটি object বানান এবং তাদের তথ্য print করুন।✨ Show Answer (উত্তর দেখুন)
Main.javaclass Student { String name; double cgpa; Student(String n, double c) { name = n; cgpa = c; } void describe() { System.out.println(name + " — CGPA " + cgpa); } } class Main { public static void main(String[] args) { new Student("Arif", 3.72).describe(); new Student("Nila", 3.91).describe(); } } -
Extend the
Walletexample to reject deposits of zero or negative amount. Run it.Wallet-এ শূন্য বা ঋণাত্মক deposit বন্ধ করুন।✨ Show Answer (উত্তর দেখুন)
Main.javaclass Wallet { String owner; double balance; Wallet(String o, double b) { owner = o; balance = b; } void deposit(double amt) { if (amt <= 0) { System.out.println("Invalid amount"); return; } balance += amt; System.out.println(owner + " balance: ৳" + balance); } } class Main { public static void main(String[] args) { Wallet w = new Wallet("Arif", 100); w.deposit(50); w.deposit(0); w.deposit(-10); } } -
Explain in 3 sentences why abstraction is essential when designing a ride-hailing app (like Pathao).Pathao-এর মতো অ্যাপে abstraction কেন জরুরি — ৩ বাক্যে লিখুন।
✨ Show Answer (উত্তর দেখুন)
Answer: (1) A ride-hailing app must track vehicles, drivers, riders, and trips — without abstraction the code quickly becomes unmanageable. (2) Abstraction lets us treat every
Vehiclethe same way (get location, compute ETA) regardless of whether it is a bike, car, or CNG — the caller doesn't care. (3) That simplifies matching, pricing, and UI code, and lets a new vehicle type be added without rewriting the rest of the system. -
Design a class
Transactionwithfrom,to,amount,timestampand asummary()method. Create one and print it.Transaction class design করে একটি object তৈরি ও print করুন।✨ Show Answer (উত্তর দেখুন)
Main.javaclass Transaction { String from, to; double amount; long ts; Transaction(String f, String t, double a, long s) { from = f; to = t; amount = a; ts = s; } void summary() { System.out.println("[#" + ts + "] " + from + " → " + to + " : ৳" + amount); } } class Main { public static void main(String[] args) { new Transaction("Arif", "Nila", 250.0, System.currentTimeMillis()).summary(); } }
Summary — Module 02
Great Java starts in the head. Decompose the problem, abstract away noise, find patterns, design an algorithm — then map nouns to classes, verbs to methods, adjectives to fields. A class is a blueprint; an instance is a real object. UML is a one-page design language; use it. The four OOP pillars — encapsulation, inheritance, polymorphism, abstraction — are the tools we will spend the next several modules mastering.