Actually, between objects of the real world and representations, there is another layer: Terms & Informations.
In writing your question here, you have already used all three of those layers. Or maybe even just two. You have an abstract idea of what a car is. Something with four wheels, a motor, at least one dorr, at least one seat, a steering wheel and so on. But if you ask ten people to draw a car, they will all draw different things. The details are all different. And yet, when we talk about the abstract idea of a car, we have an idea of what is meant by it and can effectively communicate.
In fact, the three letters "car" are already a representation of that abstract concept. I could have easily written "Auto" (in german), "macchina" (italian) and so on, and it would all still be representations of the same abstract idea.
If we put the real world on the left, and the representation on the right, we can create the following diagram:
Abstraction Presentation
----------------------> --------------->
Real World Terms, Information Representations
<----------------------- <---------------
Understanding, Interpretation
Comprehension
In the real world, you have a real car. But not all cars are the same. All cars are different. but we can abstract those differences away and get an abstract concept of a car. this is not the same as the letters that make up the word "car". The three letters 'C', 'a', 'r' forming the word "car" are already a representation of this abstract idea. A comic image would also be. So would a photo. Or the word "Auto" or "macchina". All different representations -- in different languages or media types -- for the same concept.
You can easily see that in order to write your question, the word "car" had to be stored in memory on your compuer, then on the many servers in between you and me, and finally on my computer. This representation of a car was and is in the memory of my and your computer. Its is one of the many ways how you could represent a car in memory. It just turns out that this representation is super useful for writing to each other, but absurdly unsuitable for writing a simulation involving cars as an OOP program.
Most books skip these details because we humans do this all the time, and going from the left to the right or right to the let in the above diagram is fairly easy in a lot of cases.
However, when you design a computer program, you need to put a little bit more work into it. Which properties of real cars are interesting to me? Those are the properties you need to model. And finally, when you create a new car by doing var myCar = new Car()
, then you are creating an in-memory representation of some car. You can't say exactly which real car. Or if you have a database tracking e.g. the number plate, you can even say which real car. But the in-memory representation of the car is not the real car, and is also isn't the abstract idea of a car. Its a representation of some car.
We use our programs to model properties of those representations and how they interact. But in the end, its the human mind that gives meaning to it by interpreting what we see on the monitor.
Even if we use those representations to remotely drive real cars around - the representation still isn't the real car. Just one way to represent it. In a way our program can use it. In a way we can use it.
Numbers, for example, have been represented over the years in many different ways.
The following are three representations of the same number, which have all been in use and continue to be in use today:
|||| = IV = 4
Using vertical bars is still done, I do it in my sports team to keep count of scores. Roman numerals are ubiquitous in Europe. And finally, the arabic representation of the same number.
Fun question: What is 0 "in the real world"? Abstractly, its the idea of nothingness. But what is nothing in reality? Food for thought.
car_object.drive()
should not result in an actual car driving somewhere, and indeed for most object computer systems, they ultimately derive their value from the fact that they cause things to happen in the real world. Thedrive
method may operate on bits in memory, or it may send messages to robotics that control a car - the point of encapsulation is that you don't need to know when you write the code.