File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Context Object Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Context Object Pattern" Watch "Context Object Pattern" New topic

Context Object Pattern

Aravind Ram

Joined: Mar 06, 2008
Posts: 22
Hi all,

I've understood the J2ee patterns except Context Object Pattern.

Can somebody explain the Context Object Pattern, like its purpose ,how it is used and in what scenario it is used with an example if possible.

Thanks in advance !!
Aravind Ram
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Where did you see a Context Object Pattern

Lann Lu
Ranch Hand

Joined: May 31, 2008
Posts: 45
Please google it, there are plenty of resources talking about this pattern, It is explained there much better than me. :-)

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Thanks Tao
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
In short it decouples software components from protocol-specific API.

For example, Web MVC framework such as Spring MVC, it creates domain object from ServletRequest, so we can have software components that work with domain object, that improves reuseability (can be used outside a web container) and testability (can be tested without a web container).

SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Sorin Alexandru

Joined: Nov 30, 2008
Posts: 28
Context Object wraps protocol specific information, such as HTTP and hides that from its clients. So it decouples the clients from the protocol-specific functionality.
A typical usage is:
- a FrontController creates a RequestContext object which wraps the HttpServletRequest
- the FrontController passes the RequestContext object to the ApplicationController
- now the ApplicationController is totally unaware of HTTP, so it works at a higher level of abstraction, e.g.: requestContext.getSomeParameter()
- the ApplicationController might pass the RequestContext object further, to a Command object (implementing the Service to Worker pattern)
- etc.
Aravind Ram

Joined: Mar 06, 2008
Posts: 22
Thanks Sorin ...
I agree. Here's the link:
subject: Context Object Pattern
Similar Threads
J2EE Context Object design pattern
Connection pooling design pattern
POJO class + Singleton
what is config object ?
Inversion of control