Object-oriented – What does “representing” something in memory mean in OOP

object-orientedterminology

While learning about OOP, I have found that the term "represent" is used a lot in OOP tutorials. For example I may find a statement like this: "a car object represents a real life car" (of course an object can represent anything, not just real life entities).

My question is, what does the term "represent" mean in this case, does it mean the following:

  • We can't actually put a real life car inside of computer memory!! but
    we can put in memory some data (variables) that describe a real life
    car (for example: color, speed, etc.), and we can also put some functionality
    (methods) that describe the functionality of a real life car (for example: drive(), stop(),
    etc.), and these combined variables and methods are a car object.

  • And then we can "imagine" or "pretend" that the car object in memory
    is actually a real life car, so for example when we do car_object.drive(),
    we can "imagine" or "pretend" that there is an actual car that is
    being driven (even though in reality what is happening is that some
    variables in memory are being manipulated, and not an actual car is
    being driven!!).

Am I correct in my understanding?

Best Answer

This question is not specific to software engineering: it applies to all disciplines working with information.

In 1929, the Belgian surrealist painter René Magritte explained it very intuitively in a masterpiece of art called the treachery of images: the painting shows a pipe on a uniform background, and a caption in French "This is not a pipe". It looks totally absurd, because you see a pipe, so why shouldn’t it be a pipe? This is because it’s not a real pipe. If he’d expressed it positively, he would have written "This is a representation of a pipe".

You explained it appropriately for OOP: a representation of a Car is not a car; you can’t use the Car in memory to drive home. In The Sims your avatar (your representation) could use it to go to the representation of your home. By the way, even in the game, The Car representation in memory (properties about the car, its state, and a 3D model) is different from the visual representation of the car representation on the screen (2D picture made with shapes and colors).

But there’s more behind it. The information in memory is just a set of bits. We decide what it represents. Take for example a simple byte 0b1000001. The same byte value could represent 65 if we want it to be an integer, A if we want it to be an ASCII character, a RES control code if we want to use it as EBCDIC character or even a set { garden, terrace } if we decide that it’s a bit encoding of a set where the 7th bit corresponds to a terrace and the first bit a garden.

In memory, there are only bits. The representation is the mapping we do to give them some kind of meaning. For an OOP object, that mapping is done between the values in memory and the state of the object and the methods that make its behavior. How is, of course, language specific (examples: C++, Java).

Related Topic