Object-oriented programming (OOP) is a programming paradigm in which software is organized around objects: entities that expose operations and may maintain state across those operations. Objects interact through method calls, messages, or other explicitly defined interfaces. Many object-oriented languages group objects into classes and support inheritance, but class-based inheritance is not essential to every object-oriented system. Prototype-based languages, for example, organize behavior through relationships among individual objects.
OOP is important in software engineering because it provides ways to divide large programs into components with explicit responsibilities and controlled dependencies. Its mechanisms underpin many graphical user interfaces, application frameworks, simulation systems, and business applications. They are supported by numerous programming languages, although languages differ substantially in what an object is, how operations are selected, and how state is protected.
The familiar description of OOP through encapsulation, abstraction, inheritance, and polymorphism is a useful teaching framework rather than a universally accepted definition. Historically, object orientation developed through several traditions, including simulation, message passing, abstract data types, and interactive computing. Understanding it therefore requires distinguishing object models and language mechanisms from design practices, implementation techniques, and claims about software quality.
Historical development
Object-oriented programming emerged from efforts to represent complex systems as interacting computational entities. At the Norwegian Computing Center, Ole-Johan Dahl and Kristen Nygaard developed Simula during the 1960s, initially to support discrete-event simulation. Simula I provided simulation-oriented facilities, while Simula 67 introduced a more general class mechanism, class prefixing, and virtual procedures. Its objects could represent simulated processes with persistent local state rather than merely records passed between unrelated procedures.
Simula’s importance extends beyond simulation. Class prefixing established an influential model for extending existing descriptions with additional data and operations, anticipating later inheritance mechanisms. An object could retain its own variables while participating in a larger network of interactions. These ideas offered a way to structure programs around entities whose lifetimes and behavior mattered independently of the immediate sequence of procedure calls.
At Xerox PARC during the 1970s, Alan Kay, Dan Ingalls, Adele Goldberg, and colleagues developed Smalltalk. Smalltalk-72 explored a message-oriented style, while subsequent versions refined a more regular language and programming environment. Smalltalk-80 became a major reference point for object-oriented systems. Its environment combined objects, interactive tools, graphical interfaces, and facilities for examining and modifying a running system. Classes themselves were objects, and much of the system’s behavior was expressed through message sending.
A separate route brought object orientation into systems programming. Bjarne Stroustrup began “C with Classes” at Bell Labs in 1979, combining ideas influenced by Simula with compatibility and efficiency goals associated with the C programming language. The name C++ was adopted in 1983, and its first commercial release followed in 1985. Unlike Smalltalk, C++ supported object-oriented programming alongside procedural and other styles, with explicit attention to resource control and low-level representation.
During the 1980s and 1990s, object orientation spread through workstation software, graphical application libraries, and enterprise development. Objective-C combined C with Smalltalk-inspired messaging; Eiffel emphasized contracts and systematic class design. Java, publicly introduced in 1995, combined a class-based model with managed execution. JavaScript, also introduced in 1995, adopted prototype-based objects rather than Java’s class model. C#, introduced in 2000, became another prominent managed, class-based language.
These developments did not produce a single standardized object model. Instead, object orientation became a family of related approaches. Later languages frequently combined it with functions as values, generic programming, pattern matching, and other mechanisms, making multiparadigm programming more representative of practice than exclusive adherence to one style.
Objects, state, behavior, and identity
An object is commonly described through three properties: state, behavior, and identity. State consists of information associated with the object at a particular time. Behavior consists of the operations it supports. Identity distinguishes the object from other objects, even when they contain equal information. These properties are conceptual: a language implementation may optimize away a physical object while preserving its observable behavior.
A bank-account object illustrates the distinction. Its state might include a balance and account status. Its operations might include depositing funds, recording a withdrawal, or closing the account. Two accounts can have the same balance without being the same account. Conversely, one account remains the same account after its balance changes. Identity therefore concerns continuity and reference, not simply the equality of stored values.
Many languages distinguish identity comparison from value comparison. In Java, reference equality compares whether two references designate the same object, whereas an appropriately implemented equals method can compare logical values. In Python, is tests identity, while == invokes equality behavior. The meaning of equality is not automatically supplied by object orientation: language rules and individual type definitions determine it.
References permit several parts of a program to designate the same object. This creates aliasing, which is useful for shared structures but complicates reasoning about mutation. If two components hold references to one mutable list, an update through either reference may be observable through the other. A function that appears to inspect a local object can therefore depend on changes made elsewhere. Object boundaries alone do not eliminate shared-state problems.
Not all objects are mutable entities. A monetary amount, date, coordinate, or color can be modeled as a value whose identity is irrelevant and whose observable contents never change. Such objects are often compared by value and replaced rather than modified. Distinguishing entities from values helps clarify whether a program must preserve continuity over time or merely represent information accurately.
Objects can also form complex graphs. A document may refer to paragraphs, a paragraph to style information, and several paragraphs to the same style object. Cycles arise when children refer to parents or when collaborating objects refer to one another. Such relationships affect traversal, copying, persistence, and memory reclamation. A shallow copy preserves references to nested objects; a deep copy attempts to duplicate some or all of the reachable structure. Neither operation has one universally correct meaning, because sharing and identity may themselves be part of the intended model.
Encapsulation and behavioral contracts
Encapsulation groups state and operations behind a boundary that limits how clients interact with a component. It is closely associated with information hiding, the design principle that implementation decisions likely to change should be concealed behind stable interfaces. The two ideas overlap but are not identical: a class can syntactically group fields and methods while exposing nearly every representation detail.
A useful encapsulated object protects an invariant—a condition that must hold whenever the object is available for ordinary use. A bounded queue, for example, may require that its recorded size remain between zero and its capacity. Queue operations coordinate changes to storage, indices, and size so that clients do not need to maintain those relationships themselves. Making the fields private helps prevent accidental interference, but correctness still depends on the methods preserving the invariant.
An application programming interface expresses what clients may rely on. Its contract includes more than method names and parameter types. It may specify permitted inputs, returned results, error conditions, ordering guarantees, mutation effects, and performance expectations. Two implementations with identical method signatures can be behaviorally incompatible if, for example, one preserves insertion order while another explicitly does not.
Design by contract, particularly associated with Bertrand Meyer and Eiffel, makes these obligations explicit through preconditions, postconditions, and invariants. A precondition states what must be true before an operation; a postcondition states what the operation guarantees afterward. In a stack, popping might require that the stack be nonempty and guarantee that the returned value was previously at its top. Contracts may be documented, checked at runtime, or analyzed by tools.
Representation exposure can defeat an otherwise private design. If an object returns a direct reference to its mutable internal collection, callers may alter that collection without using the intended operations. Defensive copying, immutable representations, restricted views, and controlled iteration are different responses. Each has trade-offs involving copying cost, convenience, and whether clients need to observe subsequent updates.
Encapsulation is not automatically a security boundary. Language-level access restrictions generally organize trusted code; they do not necessarily isolate hostile components, native extensions, or code using powerful runtime facilities. Stronger protection may require process boundaries, restricted capabilities, or an application sandbox. The relevant distinction is between discouraging accidental dependence and preventing an adversary from exercising authority.
Good encapsulation also does not require hiding everything. An interface should reveal the information necessary for correct use while withholding incidental representation choices. The objective is a comprehensible dependency boundary, not the largest possible number of private declarations or trivial getter and setter methods.
Classes, prototypes, and object creation
A class commonly defines a family of objects with related representation and behavior. It may specify instance fields, methods, initialization rules, and relationships to other classes. An instance is an object created according to that definition. However, the relationship between a class and a type varies by language: some languages identify them closely, whereas others separate implementation classes from the interfaces or types they satisfy.
Instance members belong conceptually to individual objects. Class or static members belong to the class-level structure rather than to each instance. For example, each connection object may maintain its own network endpoint, while a class-level factory creates connections. Static operations usually do not select behavior according to an individual receiver’s runtime class, although exact rules differ among languages.
Constructors establish an object’s initial state. They may validate inputs, initialize parent-class state, acquire resources, or connect the object to collaborators. A factory method can separate the public creation operation from the concrete class being instantiated. This supports implementation substitution, caching, pooling, and choosing among several representations. Creating an object is therefore not always synonymous with allocating a fresh memory region.
In prototype-based programming, objects can obtain behavior through other objects rather than exclusively through class definitions. An object may contain its own properties and delegate unsuccessful property lookup to a prototype. A prototype chain supplies a lookup path. Adding or replacing a property on a particular object can specialize its behavior without defining a new class.
JavaScript illustrates this model. Ordinary objects have an internal prototype relationship, and property lookup can proceed through that relationship until a matching property is found or the chain ends. Its class syntax provides structured declarations, constructors, and inheritance-related facilities on top of the prototype-based object model. That syntax is not identical in every respect to manually assigning properties: class bodies also have specific rules for strict execution, method definitions, and private elements.
Prototype delegation must be distinguished from copying. Cloning an object may duplicate its current properties, while delegation allows later lookup to reach another object. Whether later changes are visible depends on which object owns the property and whether an intervening object shadows it. This difference matters in dynamically extensible systems.
Some languages make classes themselves ordinary runtime objects, with metaclasses determining their behavior. Others expose classes through restricted metadata or treat them mainly as compile-time constructs. Consequently, statements such as “everything is an object” describe particular language designs rather than a universal requirement. The practical questions concern creation, lookup, modification, and the guarantees available to clients.
Message sending, dispatch, and polymorphism
Polymorphism allows code to operate across more than one concrete form. In object-oriented systems, its most characteristic form is subtype polymorphism: a client uses a common interface while different objects provide different implementations. A drawing program can ask each shape to draw itself without placing all shape-specific logic inside one central conditional statement.
The mechanism that selects an operation’s implementation is called dispatch. With dynamic dispatch, selection depends at least partly on runtime information, often the receiver object’s class. A call such as shape.draw() may invoke a circle implementation or a rectangle implementation according to the actual object referenced by shape. The variable’s declared type determines which operations are permitted, while the runtime receiver can determine which implementation executes.
Method overriding supplies a specialized implementation of an inherited operation. Overloading is different: several operations share a name but differ in their parameter signatures. In languages such as Java and C++, overload selection is largely performed using compile-time information; an operation selected this way may subsequently involve dynamic dispatch. Confusing these stages obscures why apparently similar calls sometimes behave differently.
Single dispatch selects primarily on one distinguished receiver. Multiple dispatch selects an implementation using the runtime types or classes of several arguments. The Common Lisp Object System provides generic functions whose methods can specialize on multiple arguments. This can be useful for operations such as combining shapes or handling interactions between several independently varying kinds of object. Multiple dispatch also requires rules for resolving competing applicable methods.
Message sending emphasizes requesting behavior from an object rather than directly manipulating its representation. In Smalltalk, ordinary computation is extensively expressed through messages. The term does not imply a network operation or asynchronous execution: a local message send can behave like a synchronous method call. Conversely, some systems queue messages and process them later, giving message sending a different execution model.
Not every operation associated with an object is dynamically dispatched. Languages may support nonvirtual methods, static methods, extension methods, or final methods that cannot be overridden. A runtime may also optimize a virtual call into a direct call when it can prove the target implementation. Such optimization preserves the dispatch semantics even when the generated instructions no longer perform a general lookup.
Polymorphism reduces some dependencies but introduces others. A caller can become independent of concrete classes while depending strongly on the common interface’s semantics. Successful substitution therefore requires more than finding a method with the expected name. Return values, side effects, failures, and behavioral guarantees must also satisfy the expectations attached to that interface.
Inheritance, subtyping, and substitutability
Inheritance allows one class or object description to derive features from another. It can reuse implementation, establish a classification relationship, or contribute to a type hierarchy. These roles are related but distinct. Reusing code does not by itself justify treating one abstraction as a behavioral substitute for another.
Subtyping concerns where a value of one type may be used in place of a value of another. The Liskov substitution principle, associated with Barbara Liskov’s 1987 account of data abstraction and hierarchy and later work with Jeannette Wing, expresses a behavioral requirement: properties established for objects of a supertype should remain valid for objects of its subtypes. A subtype should not surprise a client that follows the supertype’s contract.
In contract terms, an overriding operation should not demand stronger preconditions than clients of the parent interface were required to meet. It should not provide weaker postconditions than those clients were promised. Maintaining relevant invariants and constraints on state evolution also matters. Signature compatibility alone cannot establish these properties.
The familiar rectangle-and-square example exposes the difficulty. Mathematically, every square is a rectangle. But a mutable rectangle interface may allow width and height to be changed independently. A square that preserves equal sides cannot honor that same expectation for every operation. The conflict arises from the behavioral interface and mutation model, not from geometry. An immutable shape interface with different operations may admit a different, coherent subtype relationship.
Inheritance also creates coupling between parent and child implementations. A parent method may call an overridable operation, allowing a child implementation to affect behavior far from its apparent point of extension. Changing the parent’s internal call structure can therefore break descendants even when public signatures remain unchanged. This family of problems is often described as the fragile base class problem.
Multiple inheritance permits a class to derive from more than one parent. It raises questions about name conflicts, repeated ancestors, method order, and whether shared ancestors contribute one or several state components. C++ provides virtual inheritance to address shared base subobjects in certain diamond-shaped hierarchies. Python uses a method resolution order based on C3 linearization. Interfaces, mixins, and traits provide other ways to share obligations or behavior, with language-specific conflict rules.
Inheritance is consequently an extension mechanism with substantial semantic costs, not an automatic measure of design quality. Shallow hierarchies with stable contracts can be effective. Hierarchies constructed mainly to share a few lines of code can impose relationships that later changes make difficult to preserve.
Composition, delegation, and design patterns
Object composition constructs behavior by assembling objects that hold references to collaborators. Instead of deriving a new class from an existing implementation, a component can contain an object that performs part of its work. A report generator might collaborate with a data source, a formatter, and an output destination, allowing these responsibilities to vary independently.
Delegation occurs when one object forwards responsibility for an operation to another. It is more than mechanical forwarding when the receiving object supplies context, controls access, or combines the result with other behavior. A caching repository can delegate retrieval to another repository while storing selected results. A wrapper may expose the same interface as its wrapped object or a deliberately different one.
“Favor composition over inheritance” is a design guideline rather than a prohibition. Composition often makes dependencies explicit and permits runtime replacement of collaborators. It can also create additional objects, forwarding code, and configuration complexity. Inheritance can be appropriate when a framework intentionally defines stable extension points or when a language’s abstraction model makes the subtype relationship clear.
Software design patterns name recurring arrangements of responsibilities and collaborations. The 1994 book Design Patterns, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, organized 23 influential patterns into creational, structural, and behavioral categories. The patterns describe design problems and trade-offs; they are not language-independent rules requiring identical implementations.
Strategy separates a varying algorithm from the object that uses it. A route planner, for example, can receive a routing strategy rather than encode every routing policy in one class. Observer describes subscriptions through which changes trigger notifications, as in graphical interfaces. Decorator adds behavior through wrapping, while Adapter translates one interface into another. These mechanisms address different dependency problems even when their implementations all involve references and forwarding.
Patterns can become unnecessary ceremony when a language already provides a simpler mechanism. A first-class function may express a strategy without a dedicated class hierarchy. Iteration syntax may incorporate the role once filled by an explicitly constructed iterator object. Pattern terminology remains useful for discussing intent, but the amount of code required depends on the language and surrounding libraries.
Dependency injection supplies collaborators from outside a component instead of constructing them internally. This can separate application policy from assembly and make alternative implementations easier to test. It does not require a container or framework: an ordinary constructor parameter can perform injection. The essential issue is who chooses dependencies and how visible that choice remains, not whether the application uses a particular configuration technology.
Type systems, interfaces, and generic programming
A type system determines which program operations are permitted and what guarantees can be established about them. Object orientation is compatible with both static and dynamic typing. Static typing checks many constraints before execution; dynamic typing checks relevant operations as execution proceeds. Neither category determines whether a language supports encapsulation, inheritance, or mutable objects.
Nominal typing relates types through explicit declarations and names. A class implements a named interface because its declaration establishes that relationship. Structural typing instead examines the required members or operations. In TypeScript, many object compatibility decisions are structural: an object can satisfy a type by providing the required shape without explicitly declaring the corresponding relationship.
Duck typing is a runtime-oriented practice in which code relies on an object supporting the needed behavior rather than first requiring membership in a declared hierarchy. A function may accept any object with a suitable read operation. Structural static typing and duck typing share an emphasis on available operations, but they differ in when and how compatibility is established. Neither automatically verifies that two identically named methods have the same meaning.
Interfaces separate a contract from a particular implementation, although some languages also permit interfaces to include default behavior. Abstract classes can combine incomplete behavior with shared representation or implementation. The distinction varies across languages: the relevant questions include whether instances can be created, whether state can be stored, how many parents are permitted, and which conflicts are resolved statically.
Generic programming abstracts over types as parameters. A generic collection can store elements of a specified type while preserving useful compile-time information. This is different from subtype polymorphism: generic code can operate uniformly across many type arguments without selecting behavior through an object hierarchy. Languages combine these mechanisms through bounds, constraints, traits, interfaces, or specialized compilation.
Variance describes how relationships between element types affect relationships between parameterized types. A read-only producer of a subtype can often serve as a producer of its supertype, which is covariance. A consumer that accepts a supertype can often serve where a consumer of a subtype is needed, which is contravariance. A mutable container that both accepts and returns elements generally cannot safely be covariant without additional restrictions or checks.
For example, treating a mutable collection of cats as a mutable collection of animals could allow insertion of a dog through the broader view. Different languages prevent or detect this in different ways. Java arrays permit covariant reference conversions but check stores at runtime, whereas Java generic collections are invariant by default. These design choices illustrate how object-oriented expressiveness depends on the surrounding type rules, not merely on the availability of classes.
Object lifetime, memory management, and resources
An object’s lifetime is the interval during which it exists according to the language’s execution model. Its storage duration concerns how long the underlying storage remains available. These notions can differ when storage is reused or when an object is constructed within preallocated memory. Variables, references, and objects also have distinct lifetimes: a reference can disappear while the referenced object remains accessible elsewhere.
Garbage collection automates reclamation of storage that a program can no longer use. Tracing collectors begin with roots, such as active execution state and global references, and identify objects reachable from those roots. Objects outside the reachable set can be reclaimed. Cycles do not inherently prevent tracing collection because a group of objects can be mutually connected yet unreachable from all roots.
Reference counting maintains counts of owning references and typically reclaims an object when its count reaches zero. It can offer prompt reclamation in common cases, but ordinary reference counting does not reclaim unreachable cycles by itself. Systems may combine it with cycle detection or use weak references to avoid selected ownership cycles. CPython, for example, combines reference counting with facilities for collecting cyclic garbage.
Automatic memory reclamation does not eliminate every kind of resource leak. An object can remain reachable even when it is no longer useful, such as an obsolete entry retained in a global cache. Moreover, open files, locks, sockets, and graphics resources often require timely release independent of memory pressure. A collector may reclaim memory eventually without providing the release timing required by those resources.
Resource acquisition is initialization (RAII), strongly associated with C++, ties resource ownership to object lifetime. A constructor establishes ownership, and a destructor releases the resource when the owner’s lifetime ends. Stack unwinding can invoke destructors during exception propagation. Smart pointers express forms of ownership, including exclusive ownership and shared ownership, while reducing the need for explicit deletion.
Managed languages commonly provide separate constructs for deterministic cleanup. Java has try-with-resources, C# has using, and Python has context managers used through with. These mechanisms define an explicit scope for resource use rather than relying on eventual object finalization. Finalizers and destructors are not interchangeable across languages; their timing, guarantees, and execution environments differ.
Ownership rules also constrain aliasing and mutation. Exclusive ownership can make it clear which component is responsible for release, while shared ownership makes lifetime depend on several participants. Weak references allow observation without keeping an object alive. Choosing among these models affects correctness, responsiveness, and architectural dependencies, particularly when objects represent external resources rather than only in-memory values.
Runtime representation and performance
The conceptual object model does not prescribe a single machine representation. A common implementation stores instance fields together and associates the object with metadata identifying its runtime class. Additional information may support synchronization, identity hashing, or garbage collection. Other implementations use tagged values, handles, split representations, or specialized layouts for different categories of object.
Virtual method tables are a common implementation technique for dynamic dispatch. An object or its associated metadata leads to a table containing addresses of method implementations. A virtual call selects an entry and invokes the corresponding code. Multiple inheritance can require extra adjustments or tables. These details are generally implementation conventions rather than universal language requirements, and they can interact with the application binary interface.
Dynamic dispatch can add an indirect branch and inhibit some optimizations when a call target is unknown. However, an optimizing compiler can often devirtualize a call when the concrete target is provable. Just-in-time compilers may use observed execution profiles to specialize common cases, retaining checks or fallback paths when assumptions do not hold. Inline caches record previously encountered receiver types and corresponding method targets.
Object allocation costs also vary. A runtime may allocate small objects efficiently from thread-local regions, while a compiler may avoid allocation altogether if an object does not escape its local context. Escape analysis and scalar replacement can represent an object’s fields as separate temporary values rather than as a materialized heap object. Source-level use of objects therefore does not imply a fixed number of heap allocations.
Memory layout can matter more than method-call overhead. Traversing a graph of separately allocated objects may require repeated pointer dereferences and cause cache misses. Arrays of compact values can provide better locality than collections of individually allocated objects. Memory hierarchy effects become important when programs repeatedly process large amounts of data. These considerations motivate data-oriented layouts in numerical software, games, and other performance-sensitive systems.
Object orientation does not alter an algorithm’s asymptotic complexity merely by packaging it in a class. A poorly chosen data structure remains costly regardless of its interface. Nevertheless, abstraction can conceal important operational facts, such as whether a collection lookup scans every element or whether a property access performs remote input and output. Performance contracts and profiling help distinguish representation costs from algorithmic costs.
Claims that OOP is inherently slow or effectively free are both too broad. Costs depend on the language, runtime, optimizer, hardware, workload, and design. A direct representation with predictable dispatch can be efficient, while excessive allocation, indirection, or hidden work can dominate execution even in a well-optimized implementation.
Concurrency and distributed objects
Objects provide a unit for organizing state, but they do not automatically make that state safe under concurrent computing. If two execution threads access the same mutable object without suitable coordination, their operations may interfere. A method that preserves an invariant when executed alone may fail to do so when its intermediate steps overlap another method’s steps.
Locks and synchronization mechanisms can protect critical sections. A monitor associates shared state with mutually exclusive operations and facilities for waiting on conditions. However, protecting each method individually does not necessarily make a sequence of method calls atomic. A client that checks whether a queue is nonempty and then removes an item can encounter interference between the check and removal unless the interface supplies an appropriate combined operation.
Object-oriented locking designs face problems such as deadlock, inconsistent lock ordering, and callbacks made while locks are held. A callback can reenter an object or acquire another lock in an unexpected order. Immutable objects and confinement reduce these risks by limiting shared mutation. Thread-safe collections help with particular operations but do not automatically make an entire application’s higher-level protocol correct.
The actor model organizes computation around entities that receive messages, maintain private state, and create or communicate with other actors. Actors are related to object-oriented ideas but introduce a distinct concurrency model. Message processing and isolation rules vary across actor systems. Sending a message is not equivalent to an ordinary shared-memory method call, and a response may arrive asynchronously or never arrive.
In distributed computing, an object may be represented locally by a proxy while its implementation runs elsewhere. Remote object systems, including CORBA and Java Remote Method Invocation, provided ways to invoke operations across process and machine boundaries. Their interfaces can resemble local calls, but the underlying behavior includes transmission, serialization, server scheduling, and network failure.
A remote invocation can fail after the server has performed the requested operation but before the client receives the result. Retrying may then duplicate an effect unless the protocol addresses repeated requests. Latency, partial failure, authentication, and version differences are likewise observable. Location transparency is therefore limited: hiding the physical location of an object does not remove the semantic consequences of distribution.
Service-oriented architectures and microservices often make network boundaries more explicit than fine-grained distributed-object models. Coarser operations can reduce round trips and express meaningful business transactions. Object-oriented components may still structure each service internally, but local object boundaries, deployment boundaries, and distributed consistency boundaries need not coincide.
Persistence, serialization, and external representations
Objects in memory often need to be stored in a database, transmitted between processes, or reconstructed after a program restarts. These tasks require a representation beyond the current runtime. Serialization converts selected information into such a representation, while deserialization reconstructs corresponding values or objects. The process must decide what to preserve, what to omit, and how to interpret the result later.
Serializing a tree of values is simpler than preserving a general object graph. Shared references and cycles require conventions for identifying previously encountered objects. Otherwise, serialization may duplicate shared components or recurse indefinitely. Reconstructing the same values also does not necessarily reconstruct the same identity relationships. Some formats preserve graph structure; others intentionally represent only nested values.
Text formats such as JSON naturally express null values, booleans, numbers, strings, arrays, and objects in the format’s own sense of name–value mappings. They do not automatically preserve a programming language’s class identity, methods, prototypes, or arbitrary reference cycles. A JSON object is therefore not equivalent to a fully reconstructed runtime object. Application code must define how external fields map to its internal model.
Object–relational mapping connects object models with relational storage. Relational tables organize rows according to schemas, keys, and constraints, whereas an object graph organizes runtime entities through references and behavior. A mapper must translate identity, relationships, inheritance, and updates between these representations. The mismatch is not merely syntactic because database queries operate over sets and transactions rather than arbitrary sequences of local method calls.
Lazy loading retrieves related data when it is first accessed. This can avoid unnecessary work, but it can also conceal expensive queries behind ordinary-looking property access. The N+1 query problem arises when one query retrieves a collection and then separate queries retrieve information for each member. Explicit fetching strategies, batching, and query-oriented projections address different aspects of this problem.
Persistence also requires distinguishing object invariants from transaction boundaries. Two individually valid account objects do not by themselves guarantee that a transfer is recorded atomically. Database constraints and transaction semantics enforce properties across stored records. An in-memory object model must cooperate with those mechanisms rather than assume that method boundaries automatically provide durable atomicity.
Long-lived data introduces schema evolution. Fields may be renamed, removed, or assigned new meanings while older records remain. Deserialization therefore needs explicit compatibility rules and validation. Reconstructing arbitrary implementation objects from untrusted input can also expose dangerous behavior in some serialization systems. External data formats are most comprehensible when treated as deliberate contracts rather than accidental snapshots of internal memory.
Object-oriented modeling, architecture, and testing
Object-oriented analysis and design use objects and their relationships to describe a problem domain and organize a solution. A domain object may represent an account, order, measurement, or workflow, but the model need not reproduce every real-world entity literally. Software abstractions are selected according to required behavior, consistency rules, and change boundaries, not simply by extracting nouns from a specification.
Unified Modeling Language (UML), standardized through the Object Management Group beginning in the 1990s, provides several diagram types for describing systems. Class diagrams show structural relationships; sequence diagrams show interactions over time; state-machine diagrams describe state-dependent transitions. These views can expose different design questions, but a diagram is neither an implementation nor proof that the system behaves correctly.
Architectural separation often distinguishes domain behavior from user interfaces, persistence, and external services. An order’s pricing rules need not depend directly on a particular database driver or web framework. Interfaces and dependency direction can help preserve that separation. Conversely, adding an interface for every class without a concrete boundary or variation need can increase complexity without improving independence.
Frameworks frequently invert control: application code supplies objects or overrides operations that the framework invokes. A graphical framework may call a component’s event handler when input occurs. This differs from a program that directly controls every step through a central procedure. The resulting extension points can be productive, but correctness depends on lifecycle rules, callback ordering, and the assumptions the framework imposes.
Software testing must address both individual objects and their collaborations. Unit tests can exercise an object through its public interface, checking results, state transitions, and failures. Integration tests examine interactions with databases, networks, frameworks, or other components. Testing only isolated methods can miss errors in the order and conditions under which those methods are used.
Test doubles replace collaborators for controlled tests. A stub supplies predetermined responses; a mock may check expected interactions; a fake provides a simplified working implementation. These approaches serve different purposes. Tests that specify every internal call can become tightly coupled to implementation details, while tests that ignore interactions entirely may miss important protocol requirements.
Object-oriented programs can also be analyzed with formal verification, static analysis, and property-based testing. Invariants and behavioral contracts provide useful specifications, but mutable aliases, callbacks, and inheritance complicate reasoning. A subclass may change the behavior of an inherited method indirectly through an override, and an exposed reference may allow external code to invalidate assumptions. Effective verification therefore depends on precise accounts of ownership, permitted mutation, and the behavior of collaborators.
Relationships to other paradigms and design debates
Object-oriented programming is often contrasted with procedural, functional, and data-oriented programming, but these categories overlap in practical systems. A method body can contain ordinary procedural code. An object can store functions, and a function can create or return objects. Many widely used languages support several styles, allowing different parts of one application to use different abstractions.
Functional programming emphasizes functions, composition, and, in many designs, immutable data. Object orientation emphasizes encapsulated entities and interactions. The distinction is not simply “functions versus methods”: immutable objects can support functional designs, while closures can encapsulate changing state. A closure and an object can sometimes represent similar behavior through different language mechanisms and interface conventions.
One recurring trade-off concerns extending a program along different dimensions. An object hierarchy can make it convenient to add a new kind of entity that implements existing operations. Adding a new operation across every class may require changing many classes. A data type organized around explicit alternatives and external functions often reverses that trade-off. The expression problem names the challenge of supporting both kinds of extension while preserving desirable properties such as static type safety and modularity.
Data-oriented design organizes representation and processing around access patterns, often favoring contiguous collections and batch operations. In game development, entity–component–system architectures can associate entities with data components and process those components through systems. This differs from deep inheritance hierarchies in which each entity owns a large set of virtual behaviors. Such architectures can still use objects internally for tools, resource management, or application services.
Criticism of OOP frequently targets excessive inheritance, pervasive mutable state, elaborate pattern usage, or fragmented control flow. These are substantial design risks, but they are not unavoidable consequences of every object model. Conversely, encapsulation and polymorphism do not guarantee maintainability, reuse, or an accurate domain model. Those outcomes depend on interface quality, dependency structure, testing, and how well abstractions fit the actual work.
Empirical comparisons are difficult because “object-oriented” can describe a language feature, a development method, a framework, or a style adopted to varying degrees. Results depend on task, programmer experience, libraries, and the quality of alternative implementations. Counting classes or inheritance levels does not establish software quality, and broad claims that one paradigm universally increases productivity exceed what such measurements can determine.
Current multiparadigm practice often combines objects for identity, lifecycle, and integration boundaries with immutable values, generic algorithms, and explicit data transformations. The key design questions remain concrete: which state must persist, who may change it, which operations belong together, how extensions are introduced, and which dependencies must remain stable.