2.1. Objects

In order to be a proficient object oriented programmer, you need to know about the term object. Your English teachers would have talked about this word a lot because it’s an important part of English sentences. In most cases, they probably talked about objects as nouns, which are people, places or things. For computer scientists, objects aren’t just people, places or things — basically everything in the world can be an object! And it doesn’t stop there! Computer scientists even say that you have the power to create your own objects whenever you feel so inclined.

So what are some examples of objects that you might see within object oriented programs?

../../_images/Whalemouse.png

Fig. 2.1 Here is a whale object and a mouse object.

../../_images/Treeball.png

Fig. 2.2 Trees, soccer balls, and blades of grass can also be considered objects.

../../_images/drawPeaceLove.png

Fig. 2.3 Even abstract concepts like peace and love can be considered objects!

See! I wasn’t kidding when I said computer scientists will try to describe everything as objects. And they do because their official definition of the term is super generic: an object is anything that has some state and behavior.


Damn. I thought I could sneak that in without you noticing. Let me rephrase; an object is a bundle of information and all the things we can do to interact with that information. Still a bit confused? Consider our friend the whale object. The bundle of information that makes him a whale object, as opposed to the pencil object, is quite large. This information might include the following characteristics: he is blue, large and alive; he is a mammal that lives in the sea and communicates through song.
More impressively, he can do things in this world that change some of that information (swimming makes him a tired whale while singing might make him a happy whale).

Need another example? Let’s try to conceptualize an object that is commonly used within music streaming software, the song. The characteristics that make up a song object might include: length, artist, writer, key, number of plays, and rank in the world. Obviously, we can change the data that represents the number of plays by pressing the play button – this action will increase the number of plays by 1! If the number of plays becomes large enough, we might even be able to change the song object’s rank in the world.

As long as you understand that an object is just a collection of data that can be changed by some action, then you’re good to go. But what about our computers? How do they reason 1 about objects? And how might we communicate the notion of an object to our computers so that they don’t have a temper tantrum 2?


1

I’m being really generous with the word “reason” here. Computers don’t reason about anything. They’re really dumb. Alas, it’s suprisingly difficult to talk about computers without anthropormorphizing them.

2

Look at me giving computers human characteristics again. Funnily enough, this human trait is a lot more accurate when describing computers.