what is context object design pattern?

JavaDesign Patterns

Java Problem Overview


what is context object design pattern ?

Java Solutions


Solution 1 - Java

A Context is a collection of data, often stored in a Map or in a custom class which acts as a struct with accessors and modifiers. It is used for maintaining state and for sharing information within a system. See this PDF for an indepth description. Though it can be used for efficient and effective data sharing, you should note that many are wary of the Context pattern as an anti-pattern.

Solution 2 - Java

An example for it might be the HttpSession object: you have attributes which is basically a map with String keys and Object elements. This provides state information between http requests. Another example is the ServletRequest which provides state information between Servlets.

Solution 3 - Java

See https://stackoverflow.com/questions/986865/can-you-explain-the-context-design-pattern-a-bit/16161219#16161219 for a thorough description of the pattern.

My post there also explains why it's not an anti-pattern - but the botched implementation of it is.

Solution 4 - Java

"Context" comes from "Contextual Information".

From Msu.edu:

> Contextual Information: Information that is in addition to the actual text of the document, such as date sent, sender’s identity, addressee’s identity, routing information, and return receipts.

In most frameworks (and thus the design pattern), a Context Object stores information about an incoming request and corroborating a response.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIsabel JinsonView Question on Stackoverflow
Solution 1 - JavaakfView Answer on Stackoverflow
Solution 2 - JavaTamas RevView Answer on Stackoverflow
Solution 3 - JavaGlen BestView Answer on Stackoverflow
Solution 4 - Java8bitjunkieView Answer on Stackoverflow