Quick Index
Overview


Remember we are solving problems in an object-oriented way. This means that our algorithms may include our "object universe". In other words, our algorithms will "send messages" to other objects (and "this"). Solution reuse is always the goal.

Let's now take a look at how this works -- the key is context.

Context Examples


When we are writing an oo algorithm, think of yourself as "inside" the given object you are coding -- e.g., MyArray in this case. Also see context discussion....

This means that we can use everything (ivars and other algorithms) in our context (in the box).
Let us say we are writing an algorithm for the method "findFirst" in the class MyArray.

Recall that "this" is how we reference the current object that we are writing an algorithm for.

Because the method is in the class MyArray, that means that our context is the entire red box for MyArray. I.e., all of the ivars and other methods in the class are available to use.

We would reference them like this:

  • this.array
  • this.get(myIndex)
  • this.set(myIndex, myElem)
As object coders we want to take advantage of a larger context that includes other objects.

Let's say we writing an algo for method "capitalizeWords" in class MyString. It turns out that using a MyArray object is helpful (we'll see why soon).

Our expanded context includes MyString (the class we are working in) and also MyArray (the helper class we are using -- either as ivar or local var).

Thus our context includes the two boxes as shown.