Introduction to Object-Oriented Programming

Site Admin · 11 Sep 2026 · 12 views

The OOP Mindset

Procedural programming focuses on functions that operate on data. Object-oriented programming ties the data and the functions that act on it into a single unit called an object. This mirrors the real world: a Car object has attributes (colour, speed) and behaviours (start, accelerate).

The Four Pillars

  • Encapsulation: hide an object's internal data and expose behaviour through methods.
  • Inheritance: build new classes that reuse and extend the members of existing classes.
  • Polymorphism: the same method name can behave differently depending on the object that calls it.
  • Abstraction: emphasise what an object does and hide how it does it.

Class vs Object

A class is the blueprint; an object is the real example built from that blueprint.

class Dog {                 // blueprint
    String name;
    void bark() { System.out.println(name + " says woof"); }
}

Dog d1 = new Dog();        // real object built from blueprint
d1.name = "Rex";
d1.bark();                 // Rex says woof

Why Object Orientation Helps

  • Reuse: classes are reused via inheritance and composition.
  • Maintainability: changes stay local to the class that owns the data.
  • Problem modelling: real-world concepts map naturally to classes.
  • Team scale: large teams can work on different classes in parallel.

Key Points

  • Objects combine state (fields) and behaviour (methods).
  • The four pillars: encapsulation, inheritance, polymorphism, abstraction.
  • A class is a blueprint; objects are created from it with new.
Share this post:

Comments (0)

Please login or register to comment.