Domain Modeling
Intermediate

Object Modeling and Domain Types

Use interfaces, type aliases, readonly data, branded IDs, and state types to model complex domains.

42 min
3 sections
interfaces
readonly
brands
domain
1
2
3

01. Interfaces for Extensible Object Contracts

Section 1 of 3

Interfaces are a good fit for object contracts that may be implemented by classes or extended by consumers. Type aliases are better for unions, intersections, and computed types. In app code, choose readability over ideology.

typescript
interface QueuePublisher {
  publish(topic: string, message: unknown): Promise<void>;
}

class BillingPublisher implements QueuePublisher {
  async publish(topic: string, message: unknown): Promise<void> {
    console.log("publish", topic, message);
  }
}

type BillingTopic = "invoice.created" | "payment.failed";
Back to Course