Skip to main content

OOP

Object-Oriented Programming

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/oop

In short

OOP, or object-oriented programming, is a way of structuring code around objects that bundle related data together with the functions that act on that data.

What is OOP?

Object-oriented programming organizes a program as a collection of objects, each representing a thing or concept, such as a user, an order, or a bank account. An object combines data, called properties or fields, with behavior, called methods. Most OOP languages use classes, which are blueprints that describe what each kind of object contains and can do.

OOP is usually described through four core ideas. Encapsulation hides an object's internal details and exposes only a safe public interface, and abstraction focuses on what an object does rather than how it does it. Inheritance lets one class reuse and extend another, and polymorphism lets different objects respond to the same method call in their own way.

In OOP, a class is like the architectural plan for a house, and each object is an actual house built from that plan. All the houses share the same layout, but each has its own address and paint color. Languages such as Java, C#, Python, C++, Ruby, and TypeScript support OOP, and it is common in business applications, games, and user interface toolkits.

OOP is often contrasted with functional programming, which builds programs from pure functions and avoids changing shared data. Many modern languages mix both styles. A frequent piece of OOP advice is to prefer composition, building objects out of smaller objects, over deep inheritance hierarchies, which tend to become rigid and hard to change.

At a glance

A class is a blueprint listing the data (fields) and behavior (methods) of one kind of object; every object made from it keeps its own values and shares the same methods.class Accountblueprintowner: stringbalance: numberdeposit(amount)withdraw(amount)fields: the datamethods: the behaviornewnewada: Accountowner = "Ada"balance = 120linus: Accountowner = "Linus"balance = 35objects: one class, many instances
One Account class, two accounts: each has its own owner and balance, and both can deposit and withdraw.

Key takeaways

  • OOP structures code around objects that combine data and behavior.
  • A class is a blueprint; an object is an instance created from it.
  • The four pillars are encapsulation, abstraction, inheritance, and polymorphism.
  • Favoring composition over inheritance keeps designs flexible.

Example

A simple class in TypeScripttypescript
// A class is a blueprint for creating objects
class BankAccount {
  private balance = 0; // encapsulated: hidden from outside code
  constructor(public owner: string) {}

  deposit(amount: number): void {
    if (amount <= 0) throw new Error("Amount must be positive");
    this.balance += amount;
  }

  getBalance(): number { return this.balance; }
}

const account = new BankAccount("Ada"); // an object (instance)
account.deposit(50);

Readers ask

What are the four pillars of OOP?

The four pillars are encapsulation (hiding internal details), abstraction (exposing only what matters), inheritance (reusing code from a parent class), and polymorphism (different objects responding to the same call in their own way).

What is the difference between a class and an object?

A class is a template that defines properties and methods. An object is a specific instance created from that class, with its own data.

What is the difference between OOP and functional programming?

OOP organizes code around objects that hold state and behavior together. Functional programming organizes code around pure functions and data that doesn't change; many languages, including JavaScript and Python, support both styles.

Often compared

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings