johnreypet@lio.com

Hi, I'm John Rey Petalio - a Web Developer, App Developer, and Visual Artist. I love playing Chess, and I'm currently learning Guitar and Video Editing. I love this song Padayon, and i love watching this movieS Inception, The Social Network, Interstellar and this animated movie Zootopia.

Operating Systems

My Projects

    KonektCons

    Building the future of On-demand Skilled Work

    A&A Mini Mart

    Full-stack e-commerce web application

    John Rey's Art Desktop project thumbnail - Interactive visual art portfolio

    John Rey's Art Desktop

    Interactive visual art portfolio

    Sorsogon Treasures

    Mobile tourism app for discovering Sorsogon's hidden gems and local attractions


Certificates

    Cyber Threat Management

    Cyber Threat Management

    (Cisco)

    Intro to Cybersecurity

    Intro to Cybersecurity

    (Cisco)

    Academic Achiever Certificate

    Academic Achiever Certificate

    (CCDI)

    Certificate of Academic Excellence

    Certificate of Academic Excellence

    (JNHS)

Back to Blog
Tutorial

Object-Oriented Programming: When Code Started Making Sense

February 4, 2023
7 min read
#objectoriented programming#softwarearchitecture#bestpractices

The Moment Everything Clicked

If Data Structures taught me how to organize information, Object-Oriented Programming (OOP) taught me how to organize code itself. This wasn't just another programming course—it was a complete paradigm shift that transformed my messy, procedural spaghetti code into clean, organized, and reusable solutions.

My Pre-OOP Code Horror Story

Before OOP, I was writing programs like this student management system:

❌ Before OOP: Procedural Nightmare

// Global variables everywhere!
String[] studentNames = new String[100];
int[] studentAges = new int[100];
String[] studentCourses = new String[100];
double[] studentGrades = new double[100];
int studentCount = 0;

void addStudent(String name, int age, String course, double grade) {
    studentNames[studentCount] = name;
    studentAges[studentCount] = age;
    studentCourses[studentCount] = course;
    studentGrades[studentCount] = grade;
    studentCount++;
}

void printStudent(int index) {
    System.out.println("Name: " + studentNames[index]);
    System.out.println("Age: " + studentAges[index]);
    // ... more messy code
}

The OOP Revelation

Then our professor introduced us to classes and objects. Suddenly, I could model real-world entities in code:

✅ After OOP: Clean and Organized

public class Student {
    private String name;
    private int age;
    private String course;
    private double grade;
    
    public Student(String name, int age, String course, double grade) {
        this.name = name;
        this.age = age;
        this.course = course;
        this.grade = grade;
    }
    
    public void displayInfo() {
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Course: " + course);
        System.out.println("Grade: " + grade);
    }
    
    public boolean isPassing() {
        return grade >= 75.0;
    }
}

The Four Pillars That Changed My World

1. Encapsulation: Keeping Things Private

Learning to hide implementation details and expose only what's necessary was revolutionary. No more accidental modifications of important data!

Real-World Example

Just like you don't need to understand how a car's engine works to drive it, other parts of my program didn't need to know how a Student object stored its data—they just needed to use its methods.

2. Inheritance: Building on What Exists

The concept of inheritance blew my mind. I could create a base Person class and then extend it for Student and Teacher classes:

public class Person {
    protected String name;
    protected int age;
    
    public void introduce() {
        System.out.println("Hi, I'm " + name);
    }
}

public class Student extends Person {
    private String course;
    
    @Override
    public void introduce() {
        System.out.println("Hi, I'm " + name + ", studying " + course);
    }
}

3. Polymorphism: One Interface, Many Forms

This was the most mind-bending concept. The same method call could behave differently depending on the object type:

Person[] people = {new Student("John", 20, "IT"), new Teacher("Ms. Smith", 35, "Programming")};

for (Person person : people) {
    person.introduce(); // Different behavior for each!
}

4. Abstraction: Focusing on What Matters

Learning to create abstract classes and interfaces taught me to focus on what something does, not how it does it.

My First Real OOP Project: Library Management System 2.0

Remember that library system from my database course? I completely rewrote it using OOP principles:

Classes I Created

  • Book: Properties and behaviors of books
  • Member: Library member information
  • Loan: Borrowing transactions
  • Library: Main system controller

Benefits I Discovered

  • Reusability: Same Book class for different libraries
  • Maintainability: Changes in one class didn't break others
  • Scalability: Easy to add new types of materials

The "Aha!" Moments That Stuck

Moment 1: The Constructor Revelation

Understanding constructors was like discovering that objects could initialize themselves properly. No more forgetting to set important values!

Moment 2: Method Overloading Magic

Realizing I could have multiple methods with the same name but different parameters was incredible. One search() method could handle searching by ID, name, or category.

Moment 3: Static vs Instance Understanding

Finally grasping when to use static methods versus instance methods cleared up so much confusion. Static for utility functions, instance for object-specific behavior.

"OOP didn't just change how I write code—it changed how I think about problems. Every challenge became a question of 'What objects are involved and how do they interact?'"

Common Mistakes I Made (And How I Fixed Them)

❌ Mistakes I Made

  • Making everything public (breaking encapsulation)
  • Creating god classes that did everything
  • Overusing inheritance when composition was better
  • Not understanding when to use abstract classes vs interfaces

✅ How I Fixed Them

  • Learned proper access modifiers (private, protected, public)
  • Applied Single Responsibility Principle
  • Understood "has-a" vs "is-a" relationships
  • Practiced with real-world examples

Design Patterns: The Next Level

OOP opened the door to design patterns—proven solutions to common problems:

  • Singleton: Ensuring only one instance of a class exists
  • Factory: Creating objects without specifying exact classes
  • Observer: Notifying multiple objects about state changes

Real-World Impact

OOP principles became the foundation for everything I built afterward:

Web Development

MVC (Model-View-Controller) architecture made perfect sense because I understood separation of concerns.

Mobile App Development

Android's Activity and Fragment classes were easy to understand because I grasped inheritance and lifecycle methods.

Database Design

Object-Relational Mapping (ORM) tools became intuitive because I could map objects to database tables.

💡 Career Impact

Understanding OOP made me a better collaborator. I could discuss system architecture using common terminology and design principles that other developers immediately understood.

Practical Tips for Mastering OOP

  1. Think in objects first: Before writing code, identify the real-world entities
  2. Start with simple examples: Model familiar things like cars, animals, or school systems
  3. Draw UML diagrams: Visual representations help understand relationships
  4. Refactor procedural code: Take old projects and convert them to OOP
  5. Read other people's code: See how experienced developers structure their classes

The Long-Term Perspective

OOP wasn't just a course—it was a new way of thinking that influenced every aspect of my programming journey. It taught me that good software design is about modeling reality in code, creating systems that are intuitive, maintainable, and extensible.

Years later, when I'm working on complex projects like KonektCons or my capstone A&A Mini Mart, I still rely on these fundamental OOP principles. They're not just academic concepts—they're practical tools that make complex software manageable.

To current IT students: embrace the mindset shift. OOP might seem overwhelming at first, but once it clicks, you'll wonder how you ever programmed without it.

What did you think of this post?

I'd love to hear your thoughts and experiences. Have you had similar experiences in your IT journey? What courses or concepts changed how you think about technology?

Read More Posts