What is a context object design template?

What is the context object design pattern?

+51
java design-patterns
Apr 21 '09 at 10:34
source share
5 answers

A context is a set of data that is often stored on a Map or in a custom class that acts as a structure with accessors and modifiers. It is used to maintain state and to exchange information in the system. See this PDF for a detailed description . Although this can be used for efficient and effective data exchange, you should note that many are wary of the Context pattern as an anti-pattern .

+35
Jul 16 '09 at 4:54
source share

An example would be an HttpSession object: you have attributes that are basically a map with string keys and Object elements. This provides status information between HTTP requests. Another example is ServletRequest, which provides status information between servlets.

+6
May 12 '11 at 2:26 pm
source share

The context object encapsulates web server-specific HTTP information in a more general and portable way.

Used when:

  • You have components and services that need access to system information.
  • You want to separate application components and services from the specifics of the system information protocol.
  • you want to disclose only the relevant APIs in context.

Use a context object to encapsulate state in a protocol-independent way of sharing in your application.

For more details see this article.

+5
Dec 20 '11 at 10:19
source share

"Context" comes from "Context Information."

From Msu.edu:

Contextual information: information that is in addition to the actual text of the document, such as the date of departure, sender ID, destination ID, routing information and return receipts.

In most structures (and therefore the design pattern), the context object stores information about the incoming request and confirms the response.

+3
Apr 24 2018-12-12T00:
source share

See Can you explain the context design pattern? for a detailed description of the template.

My post also explains why this is not an anti-pattern, but its unsuccessful implementation.

+2
Apr 23 '13 at 4:56
source share



All Articles