INTRO TO OBJECT-ORIENTED PROGRAMMING (OOP)
๐ INTRO TO OBJECT-ORIENTED PROGRAMMING (OOP)
โThis part is important kasi ito โyung foundation ng topic.โ
๐น What is a Programming Paradigm?
A programming paradigm is basically a style or pattern kung paano ka magsusulat ng code.
Think of it as โcoding philosophyโ.
The 3 Main Paradigms:
Paradigm | Focus | Example Languages |
|---|---|---|
Procedural | Step-by-step instructions | C, C++, Pascal |
Functional | Functions & expressions | Haskell, Scala |
Object-Oriented (OOP) | Objects + real-world modeling | Java, Python |
๐ In short: Paradigm = how you think while coding.
๐ PROCEDURAL vs FUNCTIONAL vs OOP
๐งฉ Procedural Programming
Code runs step by step
Uses variables + procedures (functions)
Very linear (top-down)
๐ Real-life analogy:
Parang recipe โ gawin mo muna step 1, then step 2, then step 3.
Key Points:
Uses procedures/functions
Data is not well protected
Harder to maintain for large programs
๐งฎ Functional Programming
Focuses on functions and expressions
Avoids loops like
for,whileFunctions are first-class citizens
๐ Real-life analogy:
Parang math formulas โ input โ output, walang pakialam sa process.
๐งฑ Object-Oriented Programming (OOP)
Focuses on objects that represent real-world things
Combines data + actions
๐ Real-life analogy:
Parang LEGO blocks โ bawat object may sariling role, pero puwedeng pagsamahin.
OOP Involves:
Creating classes (blueprints)
Creating objects (actual instances)
Making apps that use those objects
๐ Procedural vs OOP (IMPORTANT TABLE)
Procedural | OOP |
|---|---|
Focus on procedures | Focus on data |
Data not secured | Data secured |
Top-down approach | Bottom-up approach |
No real-world model | Models real-world entities |
Functions-based | Object-based |
๐ง Mnemonic:
P = Process, OOP = Object
๐ ADVANTAGES OF OOP
Why programmers love OOP ๐
โ Reusable code (less copy-paste)
โ More secure data (encapsulation)
โ Less complex for big systems
โ Easy maintenance
โ Faster development time
๐ In short: Mas clean, mas organized, mas scalable.
๐ง CORE OOP CONCEPTS (SUPER IMPORTANT)
๐ Class
A blueprint or template
Defines:
Attributes (properties)
Methods (actions)
๐ Example:
Class = Recipe
Object = Actual food
๐ง Object
A real instance of a class
Has:
Data members (characteristics)
Function members (actions)
๐ฑ Smartphone Example:
Data: color, weight, price
Functions: call(), camera(), record()
๐ Rule: Objects = nouns
โ Method
A function inside a class
Defines what an object can do
๐ Rule: Methods = verbs
๐ ClassโObjectโMethod Relationship
Class | Object (Data) | Method (Action) |
|---|---|---|
Automobile | Model, Color | Drive(), Brake() |
Dog | Name, Age | Walk(), Eat() |
๐ง Mnemonic:
COM = Class โ Object โ Method
๐ญ FOUR PILLARS OF OOP
1โฃ Data Abstraction
Show only important features
Hide unnecessary details
๐ Example:
You use Bluetooth, but you donโt care how it works inside.
๐ User sees what they need โ not the chaos behind it.
2โฃ Data Encapsulation
Wrapping data + methods in one class
Protects data from outside access
๐ Real-life analogy:
ATM โ you can withdraw money, but you canโt touch the bankโs system.
3โฃ Inheritance
Child class inherits from parent class
๐ Example:
Employee (Parent)โโโ Manager
โโโ Supervisor
โโโ Clerk
๐ Child gets shared traits + sariling features.
4โฃ Polymorphism
Same action, different behavior
Types:
Operator Overloading
+โ add numbers OR join stringsFunction Overloading
Same method name, different parameters
๐ง Mnemonic:
Poly = many | morphism = forms
๐ METHODS IN JAVA
main() Method
Entry point ng program
Always runs first
Method Header Breakdown:
Keyword | Meaning |
|---|---|
public | Accessible everywhere |
static | No object needed |
void | No return value |
main | Method name |
Why Use Methods?
Makes code cleaner
Reusable
Easier to understand
๐ If your main() looks messy, youโre doing it wrong.
๐งฑ CLASSES & OBJECTS (JAVA-SPECIFIC)
Data Fields
Variables inside a class
Can be:
static โ shared
non-static โ unique per object
Access Modifiers
Modifier | Access |
|---|---|
private | Class only |
public | Everywhere |
๐ Private = security
Getter & Setter Methods
Getter โ get value
Setter โ set/change value
๐ Naming rule:
getEmpNum()setEmpNum()
๐งช OBJECT INSTANTIATION
Creating Objects:
Employee emp = new Employee();What happens?
newallocates memoryConstructor initializes object
๐ Object = reference to memory
๐ง FINAL QUICK RECAP (CHEAT MODE)
๐งฉ OOP Pillars
A-E-I-P
Abstraction
Encapsulation
Inheritance
Polymorphism
๐ Structure
Class โ Object โ Method
๐ง Rules to Remember
Objects = nouns
Methods = verbs
Private = protected data
main() runs first
๐ง MEMORY TRICKS (EXAM-SAVER ๐ฏ)
Blueprint = Class
Instance = Object
Action = Method
Hide details = Abstraction
Protect data = Encapsulation
Parent โ Child = Inheritance
Same name, diff behavior = Polymorphism