liveBook · Manning

Object-oriented programming

As explained in Grokking Software Architecture

A programming paradigm that organizes software around objects containing state and behavior, commonly using classes, encapsulation, inheritance, and polymorphism.

Object-oriented programming (OOP) organizes software as self-contained objects that pair data with behavior. This can keep changes to one part of a system from breaking another, especially when the system must handle new kinds of things over time. section 3.8

Four ideas help make objects flexible and modular:

  • Encapsulation keeps an object's data and the methods that manage it together, shielding internal state behind a public interface. section 3.4
  • Abstraction exposes essential features while hiding implementation details, like taking a photo without managing the camera's inner workings. section 3.4
  • Inheritance lets a new class take properties and methods from an existing class, then add its own features. section 3.4
  • Polymorphism lets different objects respond to the same operation; classes and virtual methods helped establish this approach. section 3.4 section 3.8

A changing hospital simulation

In Simula, Patient objects could carry their own data and behavior. A TreatmentRoom could handle different patient classes, and a new EmergencyPatient type could be added without changing the room's code. section 3.8

Figure 3.3 OOP principles in picture form.

A visual summary of the OOP principles. section 3.4

How Grokking Software Architecture covers it

How deep it goes
Defines four OOP pillars with analogies and traces OOP's origins through Simula, without showing implementation code.
Examples
Uses smartphone and camera analogies, app classes, and a Simula hospital with patient types and a TreatmentRoom.
What you can do after
Understand how objects can model changing systems and support modular extensions.
How it connects
Connects OOP to SOLID principles, encapsulation, abstraction, inheritance, polymorphism, classes, and the Open/Closed Principle.

Also explained in

Compare how 13 books explain object-oriented programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.