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, while

  • Functions 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 strings

  • Function 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?

  • new allocates memory

  • Constructor 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