J2EE pattern • Integration
J2EEIntegrationJava example
Context Object solves a specific structural problem in the design.
Bundle request-scoped data so collaborators can share execution context cleanly.
Pattern overview
J2EE pattern
Bundle request-scoped data so collaborators can share execution context cleanly.
Intent
Encapsulate protocol, request, or execution context in a reusable object shared across components.
Problem
Relevant request metadata is spread across many parameters or global access points.
Solution
Create a dedicated context object passed through the relevant execution path.
Fit and tradeoffs
FamilyJ2EE
CategoryIntegration
Best used when
- For request metadata, security context, locale, tenant, or tracing data.
Tradeoffs
- Context objects can become dumping grounds if not curated carefully.
Java example
This example is intentionally compact so the pattern shape stays easy to see.
public record RequestContext(String correlationId, String tenantId, Locale locale) {}