开发者

What, exactly, is the "Context" naming convention

开发者 https://www.devze.com 2023-03-16 05:36 出处:网络
I am trying to defi开发者_开发问答ne when to name a class as a Context and I am having a very difficult time. Could someone please define \"Context\" for me and explain when to name a class \"Context\

I am trying to defi开发者_开发问答ne when to name a class as a Context and I am having a very difficult time. Could someone please define "Context" for me and explain when to name a class "Context"?


Dictionary.com (Random House Dictionary, © Random House, Inc. 2011) defines context as:

  1. the parts of a written or spoken statement that precede or follow a specific word or passage, usually influencing its meaning or effect: You have misinterpreted my remark because you took it out of context.
  2. the set of circumstances or facts that surround a particular event, situation, etc.

The second definition is the applicable definition in this case. Taking the HTTPContext class for example, we know that the class contains information about the web site at the current moment (including the request, the response, the session, the user, etc.)

Therefore, I would define a 'Context' in this regard as a class that provides information about a particular application or service; or provides access to objects and methods that describe the current state of an application (or a particular facet of an application, such as a DataContext class in Linq To SQL or Entity Framework).


If you look up the Oxford English Dictionary for "context" it tells us:

the circumstances that form the setting for an event, statement, or idea, and in terms of which it can be fully understood:

In programming a "context" class would be a class that provides your application code or code running within a framework with a set of data or objects relevant and meaningful to the task at hand.

For example, ASP.NET's HttpContext object provides information about the current HttpRequest (cookies, headers, user agent and so on). This data is meaningful only in the "context" of the current request as it may and will change for other requests.

0

精彩评论

暂无评论...
验证码 换一张
取 消