Browse OOP reference
Objects and behaviour

What is object-oriented programming?

On this page

Object-oriented programming organises work around objects with operations that callers can request. An inventory reservation can expose confirm() and release() and enforce the legal transitions between them. A useful first design question is who has enough information to refuse an invalid request.

Worked example

Python
class Reservation:
    def __init__(self):
        self.state = "held"

    def confirm(self):
        if self.state != "held":
            raise ValueError("Only held seats can be confirmed")
        self.state = "confirmed"

seat = Reservation()
seat.confirm()
assert seat.state == "confirmed"

Python tutorial on classes

Explore class relationships in the OOP Playground

When is object-oriented programming the wrong choice?Is object-oriented programming obsolete?How does functional programming compare with OOP?

All OOP questions

Search ObjectFAQ