Reputation: 6431
This word never makes sense to me. I wouldn't understand ussualy why Database Access Objects are named with this naming convention and also i have seen many times this word used in others codes which wasn't about Database objects.
Can someone explain mean of this word in programming to someone who is not english and can give some examples about general usage in programming area ?
Upvotes: 13
Views: 13878
Reputation: 18797
in .NET AFAIK, We have Httpcontext in web and ObjectContext in Entity Framework. I'm not aware of any other use of context in .NET framework, but there may be more usages. So, here's a simple explanation about the two I know.
HttpContext:
Encapsulates all HTTP-specific information about an individual HTTP request. Properties of this class include the Request object, the Response object, the Session object, and an AllErrors property which keeps an array of Exception objects occured during the current request. It's simply a wrapper class.
ObjectContext: Quoting from : https://github.com/geersch/EntityFrameworkObjectContext
every object returned by a query (Linq To Entities, Entities SQL…) is automatically attached to an object context. This context tracks the changes applied to these objects so that it can later figure out how to persist these changes to the underlying data store.
This object context is represented by a class fittingly named ObjectContext. The ObjectContext encapsulates a couple of things, namely:
So, it seems like it is used basically when we want to manage some logically relative objects. Objects that we can put in one logical context. (e.g. entities in EF or Request/Response/Session/etc in HttpContext)
Upvotes: 6
Reputation: 3
A context stores crucial information to understand a given scenario ...
Upvotes: 0
Reputation: 390
I know this is old however the word Context has appeared even more in the language as of late. According to the MSDN a context is:
Defines an environment for the objects that are resident inside it and for which a policy can be enforced.
From this, I interpret that it is a container that must adhere to a set of rules that are global in which the Context will exist. DbContext, HttpContext, and ViewContext to name a few are very easy to pack down into that definition.
This also implies that you can define, extend, your own context on top of an existing context. An example would be to take the HttpContext and derive a RestfulContext that setups the HttpContext to handle Restful policies over Http. Likewise, you could derive a HateOasContext which would further refine what policy is applied to the objects inside the Context.
Upvotes: 0
Reputation: 93424
Something is typically called a "context" in computer programming when that something encapsulates some kind of state.
In the example of Linq 2 sql or EF, you have a Data Context, or Object Context.. these encapsulate the state of your data model, including connections and versioning.
In the case of HttpContext, it's encapsulating the state of an Http connection (which is normally considered stateless, but HttpContext tries to give state to it).
In english, if we refer to context, we refer to information surrounding something that allows you to understand the entire situation in which that something exists. For example, we may say a statement is "taken out of context". That would mean a statement by itself doesn't necessarily reveal all the information.
Out of context:
People are tasty.
In Context:
We should never say or think that people are tasty.
Without the "context", the statement has a different meaning. Programming has taken the term to similarly refer to the data surrounding something that gives it more meaning.
Upvotes: 17