我已经编程好几个月了,在课堂上经常使用的一个词是“上下文”。比如ServletContext (Java), Activity (Android), Service (Java, Android), NSManagedContext (Objective-C, iOS)。
通过查字典,我知道这个词的意思是:处境,环境,情况等。然而,因为我的母语不是英语,我不知道我应该直接翻译成什么。例如,如果我要编写一个命名为SomeClassContext的类,或者一个具有上下文参数的方法,我就不知道什么时候应该将其命名为context,因为我不理解它。
我一直在Stack Overflow上搜索上下文,但没有问题/答案能够帮助我。
如果有人能给我解释一下,我将非常高兴。
我总是认为上下文是与我正在处理的对象或结构相关的特定状态。
For example, when you are using drawRect in a view (where all drawing must be done for a view) you must always get the currentGraphicsContext into which you will issue your core graphics statements. This context contains things like bounds of the view, the stroke colour, the stroke thickness for drawing a line, the fill color for filling a closed Path etc. this context (like most others) is just the current state at this point in time. so think of the graphics context in this case as just a set of state such as
描边厚度为1.5像素
填充颜色为黑色
视界为(155,200)
笔画颜色为红色
它基本上是当前时间点的状态……