CFD
CFD

Reputation: 43

What is the general idea behind the concept of "context" in programming?

Web programming in particular? I am used to procedural programming, but I have been working with ( and understanding quite well ) some sophisticated object oriented php. One thing they keep talking about is "passing the context" or "setting the context". I would assume that this context concept would apply to more languages than php, and to more areas other than web programming, as I have also heard it used in discussions about other languages.

Upvotes: 4

Views: 2045

Answers (1)

Marnix
Marnix

Reputation: 6547

I think it is about: Passing an array or passing a bicycle around. In OO languages, you will reflect to real life situations and check how something is created there.

I have an example of a game:

Shall we give the game character a movement controller? Or should there be some static manager that does it for us? We finally chose to implement the movement controller inside the game character. He is the one responsible for its own movement, or at least his brains are. There is no puppeteer in a corner somewhere. It reflects to humans with a real brain.

The context here is checking what is what and who is who. Why is it like this in real life? Why should we implement it in another way? Being sure of your sorts of objects makes a very clear distinction in what is needed and what not.

Last example:

If I have an array with numbers, it doesn't say a thing. So if we pass it to some method that does magic, it doesn't say a thing either. We can create all sorts of arrays and just pass it to the method.

But we could also assure the array, that there must be cars in there. So this context of car becomes very important in our method and we cannot just throw in an array with number.

I hope I explained it well. This is somewhat like how I have learned it at college.

Upvotes: 2

Related Questions