Pragmatic Objects
  • Pragmatic Objects
  • What's an Object ?
  • Thinking Object
  • Practices
    • The Pragmatic Practices
    • No Getters & Setters
    • Inherit Wisely
    • Wrap Null
    • Wrap Primitives
    • Wrap Collections
    • Expose Snapshots
    • Abandon Composed Names
    • Don't Check Types
    • Minimize Knowledge
    • Immutability
    • Separate Commands & Queries
    • Abandon Statics
    • Invert Dependencies
  • Patterns
    • Domain Model
    • Always Valid
    • Wrapper
    • Command
    • Procedural Object
    • Compute Object
    • Snapshot
    • Value Object
    • Observability
  • Examples
    • Celsiuses / Fahrenheits
Powered by GitBook
On this page
  1. Patterns

Compute Object

Object representing a computation.

A compute object simply represent an equation or some sort of calculation, such as a discount price or a method to calculate a threshold.

Usually, the value is computed lazily, when a method such as amount() or compute() is called.

// Represent the amount of credits to pay for a transaction
export class CreditsToPay {
  constructor(private readonly duration: Duration) {}

  amount() {
    return this.duration.asHours() * 2;
  }
}
PreviousProcedural ObjectNextSnapshot

Last updated 1 year ago