← Back to PatternPip

DECORATOR / THE IDEA IN A MINUTE

One job.
A few optional extras.

Decorator adds behavior to an object by wrapping it in another object with the same interface.

The client keeps its familiar call. Each wrapper adds a small responsibility before or after delegating to the object inside it. Wrappers can be combined without a separate class for every combination.

What changes?
Optional behavior around an existing object.
What stays the same?
The interface the client calls: send(message).
How do extras combine?
Each decorator wraps another Sender and delegates to it.

ONE CALL, OPTIONAL EXTRAS

Wrap it. Follow the call. Unwrap the result.

Try it yourself

This is an offline notification simulator. Tracking records local acceptance, not delivery or a read confirmation.

Optional wrappers

USES SENDER

Client

send(message)

Same call for every combination.

IMPLEMENTS SENDER

LoggingSender

send(message)

Record attempt, then success or failure.

IMPLEMENTS SENDER

TrackingSender

send(message)

Record the receipt only after acceptance.

CORE BEHAVIOR

EmailSender

send(message)

Accept the message and return a receipt.

No receipt yetThe result appears after the call returns to the client.
Recorded call sequence · 0 events

Send a sample to see the actual order of calls and side effects.

Choose your extras, then send a local sample message.

Try this: send with both wrappers, then swap their order. The first wrapper to start is the last to finish.

Reduced motion is on; the whole trace appears immediately. Each run starts a fresh local sender. No real messages are sent.

Useful for independent extras.

Logging, measurements and similar optional policies can surround a service while its core job stays focused. Each chosen wrapper is a real object in the call chain.

Keep the layers understandable.

Too many wrappers make behavior harder to trace. A function or a few stable options may be simpler. Choose order deliberately and preserve the wrapped object’s contract.

Choose your next step.