Modular and Object-Oriented Design
-
Classes, Instances, and Attributes
A class describes how its instances are constructed and what operations they support. Each instance can hold its own state.
-
Methods and the Object They Operate On
An instance method receives the instance as part of a normal bound call. Its body can read or modify state belonging to that instance.
-
Instance Attributes and Shared Class Attributes
An instance attribute supplies one object's value. Access may fall back to a class attribute when the particular attribute lookup rules allow it.
-
Constructing an Object in a Valid State
A constructor can establish the properties other methods assume, so callers receive an object ready to use under its contract.
-
An Object's Representation Invariant
A representation invariant is an internal property that the object's creation and supported operations keep true.
-
Encapsulation Through Operations
Encapsulation gives callers operations with a declared meaning while allowing the object's representation to evolve.
-
Composing Objects with Separate Roles
Object composition supplies one object with collaborators handling responsibilities that can be described independently.
-
Inheritance and Behavioral Contracts
A subtype used through a common interface should satisfy the behavior that interface promises for supported calls.
-
Method Overrides and Dynamic Dispatch
A call through an object may select an overriding implementation according to the object's runtime type and language rules.
-
An Interface Defined by Supported Operations
Some interfaces describe the operations an object supports without requiring a shared named base class.
-
A Named Constructor as a Class Method
A class method can provide a meaningful alternate way to build an object while receiving the class used in the call.
-
Choosing Fields for Object Equality
A value object can define equality using the fields representing its meaning. Identity remains relevant when it represents a particular persistent entity.
-
A Value Object for Durations
A value object can pair a representation with construction and arithmetic rules that preserve the meaning of a duration.
-
Entity Identity Across Object Edits
An entity can retain its identity when mutable fields change. The chosen key and the latest snapshot describe different facts about it.
-
A Module's Public Import Surface
A module's public surface consists of names and behavior other modules are expected to import and rely on.
-
Module State and Passed Configuration
A module can hold shared values. Passing configuration explicitly provides a separate way to control which values a call observes.
-
Module Dependencies and Import Cycles
A module dependency graph shows which definitions are needed by others. Cyclic initialization can leave some definitions unavailable when they are first requested.
-
Adapting an Existing Object to Another Interface
An adapter translates how a component is called or what it returns, while preserving the meaning the receiving interface requires.
-
Composing Small Validators
Validators can check different conditions on one input and combine results under a rule for error collection or early exit.
-
Selecting a Replaceable Algorithm
A replaceable strategy gives several implementations the same role under one documented interface.
-
Separating Input Acquisition and Parsing
A parser uses supplied bytes or text to recover values. A separate reader can decide where the input comes from and when resources close.
-
Returning an Independent Collection from an Object
An object can protect writable internal state by returning a separate collection or an immutable view with a specified lifetime.
-
Domain Errors and Infrastructure Errors
A domain error explains why an operation is invalid under its rules. An infrastructure failure explains why the operation could not be completed or confirmed.
-
Delegating Part of an Object's Work
Delegation lets an object use a collaborator to perform a defined operation while keeping responsibility for the surrounding behavior.
-
Configurable Objects with Explicit Defaults
A configurable object can construct valid settings by applying documented defaults only when the caller leaves those settings unspecified.
-
The Expected Call Sequence of an Interface
An interface can specify which operations are allowed in each state, such as open before read and close after use.
-
Separating a Computation from Presentation
A computation can expose results as stable values so presentation can format those values for different readers.
-
Explicit Dependencies for a Small Module
A module becomes easier to test when operations that read outside state are selected at its entry boundary and passed where needed.
-
A Focused Interface for Data Exchange
A small public interface can define what import or export means while several private steps handle formats, conversions, and storage.
-
Replacing an Implementation Behind an Interface
An implementation can change independently when the stable inputs, outputs, failure outcomes, and observable effects of its interface survive.