Skip to content
Getting Digital

Object-Oriented Programming (OOP)

Also: OOP, object orientation, class, inheritance, encapsulation, polymorphism, object-oriented design

Object-oriented programming is a way of organising a program as objects, each holding its own data and the operations allowed on it, with classes as the templates objects are made from, so that the code models the things it is about rather than the steps the computer takes.

Assessment. Encapsulation is the most useful element of object orientation: keeping data together with the only code allowed to change it prevents the class of defect in which several places update one field in different ways. Inheritance should be used sparingly, because deep class hierarchies produce code that cannot be understood without reading many files; composition provides most of the reuse with fewer side effects.

The idea dates from Simula 67 and was named and spread by Smalltalk in the nineteen-seventies; Java, C++, C#, Python, Ruby and JavaScript in its class syntax all descend from it. MDN's three core concepts cover most of what a course teaches. A class is a template that describes what an object has and does; an instance is one object made from it, so a class called Order describes orders and each customer's purchase is an instance. Inheritance lets a class extend another, so a RefundedOrder can share everything Order defines and add the refund. Encapsulation keeps an object's internal state private behind a public set of operations, so the only way to change an order's total is through a method that also updates the tax.

Polymorphism is the fourth word on every syllabus: a method name that behaves differently depending on which class the object belongs to, so that a list of shapes can be told to draw themselves and each one knows how. In Python the whole model is lightweight, a class statement, methods that receive the instance as their first argument, and no enforced privacy beyond a naming convention; in Java every file is a class and the compiler enforces what is public. The difference matters for learners: the Python version can be learned in a day, the Java version takes considerably longer, and both teach the same four ideas.

  • Class: the description. Order has an id, a list of lines, a status and a method that computes the total.
  • Instance: one order with its own id and lines. Two instances do not share state.
  • Inheritance: SubscriptionOrder extends Order with a renewal date and overrides the total to add the period.
  • Encapsulation: nothing outside the class sets the status directly; a method named cancel checks the rules first.
  • Polymorphism: code that calls total on any order gets the right answer without knowing which kind it holds.

Where the style goes wrong is in overuse of hierarchy. Modelling a business as a tree of classes feels natural and produces the inheritance ladders that make a change to a base class ripple into every descendant. The design advice that has held since the nineteen-nineties is to favour composition over inheritance: an Order holds a PaymentMethod and a ShippingRule rather than being a PaidShippedOrder. Most modern codebases mix styles, with objects for the things that have state and plain functions for everything else, and the programming fundamentals courses teach object orientation as one tool in that mix rather than as the whole of programming. Google's automation certificate, IT Automation with Python, introduces classes in its first course at the depth an automation script needs.

In practice

A billing script keeps an order as a dictionary and updates the total in four places. One of them forgets the tax; the bug ships and is found by a customer. Rewritten as a class, the total is computed by one method from the lines, the status is changed by one method that checks the transition is allowed, and the four call sites become one. The rewrite is thirty lines longer and removes the whole category of inconsistent-state bugs, which is the trade object orientation offers.

Often confused with

Python
Python is a language that supports object orientation among other styles; object-oriented programming is the style. Python code can be written with no classes at all, and object-oriented code exists in a dozen languages.
Data Structures and Algorithms
Data structures and algorithms are about how data is arranged and how steps are ordered for speed; object orientation is about how code is organised around the things it models. A class may contain a data structure, and an algorithm may be a method on a class.

Key takeaways

  • →Four ideas: class and instance, inheritance, encapsulation, polymorphism. Encapsulation is valuable in everyday code; inheritance should be used sparingly.
  • →Favour composition: an object that holds other objects is easier to change than a deep class tree.
  • →Learn the model in Python first; the same ideas in Java take longer to write and no longer to understand.

Related concepts

  • RelatedPython

    Python's class model is the lightest place to learn the four ideas.

Where this concept sits in the field

Certifications that test this

Vendor exams whose syllabus covers this concept: facts, cost and a preparation path on each page.

FAQ

Is object-oriented programming out of date?
The pure form, where everything is a class, is. The ideas are in every mainstream language and every large codebase, mixed with functional and procedural code. A developer who cannot read a class hierarchy cannot read most production code.
Does JavaScript have classes?
It has had class syntax since 2015, built over its older prototype model. The syntax covers what most code needs; the prototype model underneath explains the behaviour when something looks odd, and MDN documents both.
What does an exam expect?
Entry-level Python exams expect classes, instances, inheritance and the vocabulary; Java-oriented exams go deeper into interfaces, access modifiers and design patterns. The free certificates in the directory stay at the first level.

Sources

The primary text this definition rests on. Read it before relying on this one.

Last reviewed 3 October 2026 · Getting Digital