2.1 OOP: Objects and Classes

The main idea of object-oriented programming is that
software systems consist of objects that have state and behavior and that communicate by messages.
What does this mean?

As the name object-oriented suggests, objects are most important in this style of programming. This contrasts with procedural languages that focus on executing procedures in the computer. Here, you may think of real-world objects such as people, cars, houses, and so on. Common characteristics of these real-world objects are that they all have a state and a behavior. For example, people have state (name, length, weight, etc.) and behavior (talk, walk, sit, ...). Cars have state (speed, direction, fuel consumption, ...) and behavior (start, accelerate, brake, stop, turn, ...).

In an object-oriented language, objects are modeled in the same way: they have state expressed in instance variables and behavior implemented with methods. The methods manipulate the variables that define state. For example, documents on a Website have state (title, URL, content-type) and behavior (open, close, reload, ... ). Screen characters have state (name, font, size, position, ... ) and behavior (draw, resize, italicize, ...). In short,

In an object-oriented language, objects consist of data (instance variables) and operations (methods) to manipulate the data.
In graphical terms:

The picture of a concrete example, the letter a, may look as follows

Key in object-oriented programming is that each object itself is responsible for carrying out tasks. This includes interaction and communication with other objects. Your car parked in front of the house is just a piece of metal that is by itself incapable of any activity. The driver has to start the car, use the brakes, etc. In OOP jargon, objects send messages to other objects. Messages may pass extra information via parameters to receiving objects. The object "typist" may send the message "resize(20)" to the letter-object to change the font size. So is a message a concrete call of a method with a list of parameters. In graphical terms messaging goes as follows:

The picture of a message with a parameter in the concrete example of a typist changing a character:

What the pictures also reveals is that the instance variables of an object are in principle encapsulated and can only be manipulated by the surrounding methods of the object. They are hidden from the outside.