Object Oriented
45 items tagged with "object-oriented"
Patterns32
Factory Method
Defines an interface for creating an object but lets subclasses decide which concrete class to instantiate, deferring instantiation to subclasses.
Abstract Factory
Provides an interface for creating families of related objects without specifying their concrete classes, ensuring products from one family are used together.
Builder
Separates the construction of a complex object from its representation so the same construction process can create different representations step by step.
Prototype
Creates new objects by cloning an existing instance (the prototype) rather than instantiating a class, useful when construction is costly or types are decided at runtime.
Singleton
Ensures a class has only one instance and provides a global point of access to it, used for shared resources like configuration, logging, or connection pools.
Multiton
Generalizes Singleton to manage a fixed, keyed set of named instances, ensuring exactly one instance exists per key through a registry.
Registry
Provides a well-known central object where shared instances or services can be registered and looked up by key, giving a single point of access without scattered globals.
Adapter
Converts the interface of a class into another interface clients expect, letting classes that could not otherwise collaborate work together.
Bridge
Decouples an abstraction from its implementation so the two can vary independently, avoiding a combinatorial explosion of subclasses.
Composite
Composes objects into tree structures to represent part-whole hierarchies, letting clients treat individual objects and compositions uniformly.
Decorator
Attaches additional responsibilities to an object dynamically by wrapping it, providing a flexible alternative to subclassing for extending behavior.
Flyweight
Minimizes memory use by sharing as much data as possible between many similar objects, separating intrinsic shared state from extrinsic context-specific state.
Proxy
Provides a surrogate or placeholder for another object to control access to it, enabling lazy loading, access control, caching, or remote access.
Marker Interface
Uses an empty interface to tag a class with metadata so other code can detect the capability at runtime via type checks, without adding any methods.
Mixin
Composes reusable units of behavior into a class without inheritance, letting unrelated classes share functionality by mixing in shared method sets.
Extension Object
Lets you add new interfaces and behavior to a class over time without changing it, by attaching extension objects that clients query for at runtime.
Private Class Data
Restricts accessor-write access to class attributes by isolating data in a separate object exposed read-only after construction, enforcing immutability and encapsulation.
Strategy
Defines a family of interchangeable algorithms behind a common interface so the algorithm can vary independently from the clients that use it.
Observer
Establishes a one-to-many dependency so that when one object changes state, all its dependents are notified and updated automatically.
Command
Encapsulates a request as an object, letting you parameterize, queue, log, and undo operations independently of who invokes them.
Iterator
Provides a uniform way to traverse the elements of a collection sequentially without exposing its underlying representation.
Mediator
Centralizes complex communication between objects in a mediator so components refer to it instead of to each other, reducing coupling.
Memento
Captures and externalizes an object's internal state so it can be restored later without violating encapsulation.
State
Lets an object alter its behavior when its internal state changes, appearing to change class by delegating to state-specific objects.
Template Method
Defines the skeleton of an algorithm in a base method, deferring specific steps to subclasses so they can vary parts without changing the structure.
Visitor
Separates an algorithm from the object structure it operates on, letting you add new operations over a class hierarchy without modifying it.
Chain of Responsibility
Passes a request along a chain of handlers, each deciding to process it or forward it, decoupling sender from the specific receiver.
Interpreter
Defines a grammar for a simple language and an interpreter that evaluates sentences in that language using a class per grammar rule.
Null Object
Provides a do-nothing object with neutral behavior in place of null, eliminating null checks and special-case handling.
Servant
Defines shared behavior for a group of classes in a separate servant object that operates on them, instead of duplicating the behavior in each class.
Active Record
Wraps a database row in an object that carries both the data and the methods to load, save, and delete itself.
Value Object
Models a concept defined by its attributes rather than identity, making it immutable and compared by value to keep the domain expressive and safe.
Anti-Patterns9
Anemic Domain Model
Domain objects that hold data but no behavior, with all logic pushed into separate service classes, draining the object model of its purpose.
Feature Envy
A method that is more interested in another class's data than its own, repeatedly reaching into that class instead of letting it own the behavior.
Refused Bequest
A subclass that inherits methods or data it does not want or use, often overriding them to do nothing, signaling a wrong inheritance relationship.
Yo-Yo Problem
An inheritance hierarchy so deep that understanding behavior forces constant scrolling up and down between many classes to trace a single call.
Call Super
A framework requiring subclass overrides to call the parent method, a fragile contract that breaks silently whenever a developer forgets the call.
Temporal Coupling
Methods that must be called in a specific hidden order, where calling them out of sequence silently breaks state with no compiler protection.
Switch Statement Smell
Repeated switch or if-else chains branching on a type code, duplicated across the codebase, that should be replaced by polymorphism.
Poltergeist
A short-lived, do-nothing class that only passes data or calls to other objects, adding indirection and noise without real responsibility.
Sequential Coupling
A class designed so its methods must be invoked in a rigid sequence, with the ordering enforced only by convention rather than by the API itself.