Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Context Object Pattern

 
Aravind Ram
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you see a Context Object Pattern
 
Lann Lu
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please google it, there are plenty of resources talking about this pattern, It is explained there much better than me. :-)

http://www.cs.wustl.edu/~schmidt/PDF/Context-Object-Pattern.pdf
http://www.corej2eepatterns.com/Patterns2ndEd/ContextObject.htm

Cheers,
Tao
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tao
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Sorin Alexandru
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sorin ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic