# Object-Oriented Programming
## Paradigms — The Codex Coding
**URL:** https://thecodex.expert/coding/paradigms/object-oriented/
**Type:** paradigm | **Confidence:** high | **Last verified:** 2026-06-01

---
## CANONICAL DEFINITION
Object-oriented programming (OOP) is a programming paradigm that organises software around objects — entities that bundle related data (attributes) and behaviour (methods) — and models programs as networks of interacting objects, structured using the four principles of encapsulation, abstraction, inheritance, and polymorphism.

---
## CONCEPT RELATIONSHIP MAP
**Requires first:** Procedural Programming · Functions · Variables
**Enables:** Classes · Inheritance · Encapsulation · Polymorphism · Design Patterns
**Commonly confused with:** Classes (a mechanism, not the definition of OOP)

---
## CURIOUS LEVEL
Objects bundle data (attributes) and behaviour (methods). Class = blueprint; object = instance. Four principles: Encapsulation (hide data, expose interface), Abstraction (expose only what's needed), Inheritance (subclass extends superclass — is-a relationship), Polymorphism (one interface, many implementations). OOP originated in Simula 67 (Dahl & Nygaard, 1967) for simulation. Alan Kay coined "object-oriented" with Smalltalk (Xerox PARC, 1972). Java (1995) made OOP the enterprise standard.

## EXPLORING LEVEL
Encapsulation serves two purposes: data hiding (prevent invalid state) and information hiding (reduce coupling). Liskov Substitution Principle (Liskov & Wing, 1994): a subclass must be substitutable for its superclass without altering program correctness. Deep inheritance = tight coupling; favour composition over inheritance (GoF, 1994). Subtype polymorphism via vtable (C++) or method table (JVM) — two pointer dereferences per virtual call. Parametric polymorphism (generics) is separate. JavaScript uses prototype-based OOP; `class` syntax is sugar over prototypes.

## COMMONLY CONFUSED
- OOP ≠ classes. Principles (E, A, I, P) can be implemented without classes (Go interfaces, JavaScript prototypes).
- Inheritance is not the most important OOP feature — composition preferred for code reuse.
- Python's `_name` convention ≠ private enforcement — convention only, not language-enforced.

## DEEP DIVE LEVEL
Simula 67 introduced classes, objects, inheritance, virtual procedures for discrete-event simulation. Smalltalk: everything is an object; everything is message-passing; late binding always. C++ vtable: each class has virtual function table; each object has hidden vtable pointer; virtual call = 2 pointer dereferences + indirect call. Python MRO uses C3 linearisation (Barrett et al., 1996) for consistent multiple inheritance. LSP formal: if ∀x:T. P(x) then ∀y:S. P(y) where S is subtype of T.

## SOURCES
1. Kay, A. C. (1993). The Early History of Smalltalk. ACM SIGPLAN Notices 28(3).
2. Liskov, B. & Wing, J. (1994). A behavioral notion of subtyping. ACM TOPLAS 16(6).
3. Gamma, E. et al. (1994). Design Patterns. Addison-Wesley.
4. Dahl, O.-J. & Nygaard, K. (1966). SIMULA. CACM 9(9).
5. Stroustrup, B. (1994). The Design and Evolution of C++. Addison-Wesley.

*The Codex Coding — thecodex.expert/coding/ — Free forever — Mumbai, India*
