到底什么是“上下文”?命名约定

发布于 2024-11-17 22:29:43 字数 66 浏览 3 评论 0 原文

我正在尝试定义何时将类命名为上下文,但我遇到了非常困难的时期。有人可以为我定义“上下文”并解释何时命名类“上下文”吗?

I am trying to define 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"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在梵高的星空下 2024-11-24 22:29:43

Dictionary.com(兰登书屋词典,© Random House, Inc. 2011)将上下文定义为:

  1. 书面或口头陈述中位于特定单词或段落之前或之后的部分,通常影响其含义或效果:你误解了我的话,因为你断章取义。
  2. 围绕特定事件、情况等的一组情况或事实。

第二个定义是在这种情况下适用的定义。以HTTPContext类为例,我们知道该类包含当前时刻的网站信息(包括请求、响应、会话、用户等),

因此,我会在这方面将“上下文”定义为提供有关特定应用程序或服务的信息的类;或者提供对描述应用程序当前状态(或应用程序的特定方面,例如 Linq To SQL 或实体框架中的 DataContext 类)的对象和方法的访问。

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

笛声青案梦长安 2024-11-24 22:29:43

如果您在牛津英语词典中查找“context”它告诉我们:

形成的情况
事件、声明或的设置
想法,并且就其而言,它可以是
完全理解:

在编程中,“上下文”类将是一个类,它为您的应用程序代码或在框架内运行的代码提供一组与当前任务相关且有意义的数据或对象。

例如,ASP.NET 的 HttpContext 对象提供有关当前 HttpRequest 的信息(cookie、标头、用户代理等)。该数据仅在当前请求的“上下文”中才有意义,因为它可能并且将会针对其他请求而改变。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文