TY

Mixed Patterns

Pragmatic blend of OOP and functional patterns — use the right paradigm for each task.

Details

Language / Topic
typescriptTypeScript
Category
Style Guide

Rules

balanced
- Use classes for stateful domain entities and services; use plain functions for stateless transformations and utilities.
- Prefer immutable data flows between components; mutate state only inside well-encapsulated objects.
- Choose the simplest paradigm for each task: OOP for modeling, FP for data pipelines, imperative for performance-critical loops.
- Encapsulate complex state and lifecycle in classes (repositories, services, controllers); keep business logic in pure functions.
- Use functional patterns (map, filter, reduce, composition) for data transformations instead of method chains on mutable collections.
- Apply dependency injection for wiring services together; prefer constructor injection for clarity and testability.
- Favor interfaces and protocols over concrete class hierarchies; combine with higher-order functions for flexible behavior customization.