what is context object design pattern?

后端 未结 5 1275
栀梦
栀梦 2020-12-02 10:10

what is context object design pattern ?

相关标签:
5条回答
  • 2020-12-02 10:53

    "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.

    0 讨论(0)
  • 2020-12-02 11:00

    See Can you explain the Context design pattern? 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.

    0 讨论(0)
  • 2020-12-02 11:01

    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.

    0 讨论(0)
  • 2020-12-02 11:02

    A context object encapsulates web server specific HTTP information in more general and portable form.

    It is used when:

    • you have components and services that need access to the system information.
    • You want to decouple application components and services from the protocol specifics of system information.
    • you want to expose only relevant APIs within a context.

    Use a context object to encapsulate state in a protocol-independent way to be shared throughout your application.

    For more detail see this article

    0 讨论(0)
  • 2020-12-02 11:07

    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.

    0 讨论(0)
提交回复
热议问题