Lesson 6 of 9 · 20m
When Language Features Replace Classic Patterns
Lambdas, iterators, generics, pattern matching, and async abstractions often remove the need for ceremony-heavy object patterns.
The classic pattern catalog assumed object-oriented languages with limited expressiveness. Modern languages quietly absorbed many of those patterns. If you implement the 1994 class diagram in a language that already has the feature, you add bulk without adding design.
Strategy is often a function
In Java before lambdas, a strategy needed an interface and a class. In TypeScript, Python, Kotlin, C#, Rust, and modern Java, a function value often does the same job.
type PricingRule = (order: Order) => Money;
const bulkDiscount: PricingRule = order =>
order.lineCount >= 20 ? order.subtotal.multiply(0.9) : order.subtotal;A named function is testable, composable, and honest. Use a class when the strategy carries configuration or collaborators; use a function when it is just behavior.
Iterator is built in
The iterator pattern is now language syntax: for x in items, for (const x of items), streams, generators. The modern design decision is not how to write iterator classes. It is whether iteration is lazy, whether it can be repeated, and whether it closes over mutable state.
def active_users(users):
for user in users:
if user.deleted_at is None:
yield userThis generator is lazy. That is powerful for large inputs and dangerous if callers expect a stable snapshot. Language support does not remove design pressure; it moves it to semantics.
Pattern matching replaces visitor-shaped boilerplate
Visitor was invented partly because double dispatch was awkward in mainstream object-oriented languages. Algebraic data types and exhaustive pattern matching often express the same operation more directly.
match event {
DomainEvent::UserCreated { id, email } => send_welcome(id, email),
DomainEvent::PasswordChanged { id } => revoke_sessions(id),
DomainEvent::UserDeleted { id } => purge_personal_data(id),
}Exhaustiveness checking is the payoff: add a new variant and the compiler points at every unhandled decision. Visitor still has a place when operations must be plugin-extensible, but it is no longer the default answer.
Decorator is often middleware or composition
Cross-cutting behavior commonly appears as middleware, interceptors, combinators, or function wrappers.
def retry(fn, attempts=3):
def wrapped(*args, **kwargs):
for attempt in range(attempts):
try:
return fn(*args, **kwargs)
except TransientError:
if attempt == attempts - 1:
raise
return wrappedThe design principle survives: same contract, composable behavior. The implementation is smaller.
Field notes
- Implement the force, not the historical shape.
- Prefer language constructs with compiler or runtime support; they carry less custom machinery.
- When a pattern becomes invisible because the language supports it, that is progress — not a missing pattern.
Was this lesson helpful?