Page 36 - Designing Autonomous Mobile Robots : Inside the Mindo f an Intellegent Machine
P. 36
A Brief History of Software Concepts
Objects
So how is an object-oriented language different from a conventional language?
Object-oriented languages still have the three basic elements of conventional lan-
guages, but they also have objects. Simply put, objects are groups of related functions
and their associated local variables. With this metamorphosis, calls to the functions
in an object are called methods, while local variables of the incorporated functions
have become properties. An object is thus a useful metaphor for a chunk of code, as
well as a way of building a protective shell around it.
Another principle of objects is that the programmer does not so much program an
object, but rather provides a blueprint of how the object will be created. This blue-
print contains code, as well as default settings for the properties. At run time, the
program itself can generate objects using these blueprints. Thus, hundreds of in-
stances of an object can be produced as needed by the application. Creating an
object from its blueprint is called instancing it. When I opened this chapter in Word,
I instanced a document object which you are reading now.
Programs are no longer static blocks of code. The actual executable code used by an
object, along with all its variable storage and other resources is created and de-
stroyed dynamically by the application. When an object is destroyed, the system
must reclaim its memory allocation, or eventually all available memory will be used
up. If this process is not completely efficient, the system will be said to experience
“memory leaks,” and applications may eventually crash as a result. Some versions of
C++ were well known for this problem.
Properties
Properties are the local variables that control the behavior of an object, or that the
object produces or acts upon. For example, if the object is a block of text, the prop-
erties might be font, size, style, and even color. This example demonstrates how
appropriate the term properties really is!
The properties of an object cannot be tampered with from outside the object, but
only by calling a method to set them. In this way, an object protects itself from
having its controlling parameters set to illegal or dangerous values. Take the ex-
ample of a program trying to set the font property of a text object. The desired font
may not be available in the computer, so the object can substitute a default font and
return an appropriate status code to let the caller know about the substitution. The
result might not be what the programmer wanted, but it is better than filling the
19

