Chapter 1: A Look at How We See the World


How do you see the world? The answer depends on your background. A scientist might see the world as molecular structures. An artist sees the world as shapes and colors. And some of us might say the world is a collection of stuff. Probably the first thing that came to mind when you read this question was, What does it matter how anyone sees the world? It matters a lot to a programmer who has to write a computer program that emulates the real world.

The Stuff That Stuff Is Made Of

Comedian George Carlin sums up how most of us see the world in his famous comedy routine. Carlin says we see the world as stuff, and he is probably right. Stuff is anything you have and anything you want. A house is stuff. Things you have in your house are stuff. Things you throw away are stuff, and so are the things you want to buy. And the stuff we have, such as a house, is made up of other stuff, such as windows and doors.

Admittedly the term stuff is less technical that you expect in a book on object-oriented programming, but it does give you a reference point to begin learning object-oriented programming.

Technically, stuff is an object. That is, a house is an object. The things you have in your house are objects. Things your throw away are objects, and things you want to buy are objects. All of us, regardless of our background, view the world as objects. An object is a person, place, thing, concept, or possibly event.

The best way to learn about objects is to examine the most important object, us. Each of us is considered an object in the world of object-oriented programming. We call this object a person .

A person as well as a house, car, and any other real-world objects are described by using two groups of features: attributes and behaviors. An attribute is a characteristic of an object. For example, a person has a first name, last name, height, and weight. First name, last name , height, and weight are attributes of all persons. As you can imagine, hundreds of other attributes characterize a person, but we ll stop at four. A behavior is an action that an object is capable of performing. A person sits, stands, walks, and runs, among thousands of other behaviors a person performs .

You can probably imagine how an automobile, airplane, and even a sales order form are objects, each having attributes and behavior. Attributes and behaviors of an automobile and airplane are fairly obvious. Both have width, height, weight, wheels, an engine, and many other attributes. An automobile and airplane move in a direction, stop, are steered to a different direction, and can perform hundreds of other actions (behaviors).

However, you might be scratching your head trying to determine the attributes and behaviors of a sales order form (see Figure 1-1). Its attributes are customer name, customer address, item ordered, amount due, and other pieces of information found on a sales order form. Its behaviors include collecting information, modifying information, and processing the sales order.

click to expand
Figure 1-1: An order form is an object that contains attributes and behaviors.

Abstract Objects and Instances

Throughout this book, you ll see how programmers view an object in two ways ”as an abstract object and as a real object. The term abstract object can seem a bit, let s say, abstract to understand. Think of an abstract object as a description of a real object minus details. For example, an abstract person is a description of a person that contains attributes and behaviors. Here are four attributes that might be found in an abstract person (notice that these attributes simply identify a kind of characteristic, such as first name or weight, but don t specify a name or measurement):

  • First Name

  • Last Name

  • Height

  • Weight

The abstract object is used as the model for a real object. A real person has all the attributes and behaviors defined in the abstract object and contains details missing from the abstract object.

For example, the abstract person is a model for a real person. The abstract person states that a real person must have a first name, last name, height, and weight. A real person specifies values associated with these attributes, such as:

  • Bob

  • Smith

  • 6 feet tall

  • 160 pounds

As you ll see in later chapters, programmers create an abstract object and then use the abstract object to create a real object. A real object is called an instance of the abstract object. You can say that a real person is an instance of the abstract person.

Some programmers like to think of an abstract object as a cookie cutter. A cookie cutter shaped as a cookie, but isn t a cookie. You might say that a cookie cutter is an abstract cookie used to define what a real cookie looks like. A cookie cutter is used to cut out real cookies from a sheet of dough. That is, a cookie cutter is used to create instances of a cookie.




OOP Demystified
OOP Demystified
ISBN: 0072253630
EAN: 2147483647
Year: 2006
Pages: 130

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net