OBJECTS are a way to group related variables and functions into a single container. That is, an entity that encapsulates data and functionality.
You can imagine an OBJECT as an “evolved version” of a STRUCT, which adds additional features. Mainly, it adds that objects have functions.
For example, considering a Car class, it could have properties like make, model, and color, along with methods like start() and stop().
- stringbrand
- stringmodel
- stringcolor
- stringBrand
- stringColor
- voidstart()
- voidstop()
These OBJECTS are defined by a class or a prototype that acts as a template or mold for creating objects. This defines the common structure (properties and methods) shared by objects of that type.
Each object created from a class is called an instance. Thus, an INSTANCE is a concrete representation of a CLASS, with its own unique data and the functionalities defined by the class.
When we create a specific object of the Car class, like a concrete car with the brand “Toyota”, model “Corolla”, and color “pink”, then we have an instance of the Car class.

OBJECTS allow us to organize and structure the data and logic of a program, promote code reuse, and facilitate its maintenance.
Each of these autonomous units, which we call OBJECTS, has the following characteristics:
- State: Represents the data and properties of the object at a given moment
- Behavior: Defines the actions and operations the object can perform
- Identity: Each object has a unique identity that distinguishes it from other objects
But, much more interestingly, objects are abstractions that allow us to model the real world. They are the foundation of Object-Oriented Programming (OOP),
Object Examples
Object-Oriented Programming has been one of the paradigms with the greatest impact on modern programming. Consequently, many languages have evolved to introduce objects into their syntax.
The details vary from one language to another. Some have a more “classical” approach, while others take somewhat different paths. But, more or less, the concept of an object is present in all languages.
Let’s see examples in some popular languages:
// Class definition
class Person
{
// Properties
public string Name { get; set; }
public int Age { get; set; }
// Method
public void Greet()
{
Console.WriteLine("Hello! My name is " + Name + " and I am " + Age + " years old.");
}
}
// Creating an object
Person person = new Person();
person.Name = "Luis";
person.Age = 25;
person.Greet();
#include <iostream>
#include <string>
using namespace std;
class Person
{
// Properties
string name;
int age;
public:
// Constructor
Person(string name, int age)
{
this->name = name;
this->age = age;
}
// Method
void greet()
{
cout << "Hello! My name is " << name << " and I am " << age << " years old." << endl;
}
};
// Creating an object
Person person("Luis", 25);
person.greet();
// Class definition
class Person {
// Constructor
constructor(name, age) {
this.name = name;
this.age = age;
}
// Method
greet() {
console.log(`Hello! My name is ${this.name} and I am ${this.age} years old.`);
}
}
// Creating an object
const person = new Person("Luis", 25);
person.greet();
# Class definition
class Person:
# Constructor
def __init__(self, name, age):
self.name = name
self.age = age
# Method
def greet(self):
print(f"Hello! My name is {self.name} and I am {self.age} years old.")
# Creating an object
person = Person("Luis", 25)
person.greet()
In the examples above, we create a CLASS called Person that defines properties (like name and age) and a method (like greet) common to all objects of that class.
Then, we create a person object using the class and access its properties and methods.
Internal Functioning Advanced
Internally, OBJECTS are handled differently from STRUCTS due to the dynamic and object-oriented nature of the languages that use them, such as Java, Python, or C++ among others.
On one hand, similar to a STRUCT, when an OBJECT is created in most object-oriented languages, a contiguous block of memory containing all its attributes is reserved.
This ensures that related data is stored together, allowing efficient access to it. The language has no problem accessing the variables, as it knows exactly how much space they occupy and their position.
But, an OBJECT also contains methods. Well, it’s most likely that in most languages the object is not stored with its methods (function references), but only stores the data, just like a Struct.
For methods, the compiler does “many things”. Some of them involve creating object methods as functions that receive the objects as parameters. This is known as a “virtual method table” or “dispatch table”.
These details happen transparently for the programmer, as the language handles it automatically. But, if you want to dig deeper, it’s a quite interesting topic.
Object-Oriented Programming Course
The emergence of objects represented one of the most important and widespread paradigms in programming, Object-Oriented Programming (OOP). The paradigm that has had the greatest impact on the way we develop software.
Logically, covering them in depth is too broad for a single article. So, if you want to learn more, I leave you the link to the Object-Oriented Programming Course.
Learn OOP, the most influential paradigm in programming
