Object

February 01, 2024

Overview

The term object has several meanings, depending on the context. The most prominent meaning is in Object-Oriented Programming (one of the most foundational programming paradigms).

Table of Contents

Object-Oriented Programming
How Are Objects Defined?
Languages Without OOP
General Computing
Software Design
Objects in Distributed Computing
Protocol Buffers
Outside of Computer Science
Next Steps

Object-Oriented Programming
^

If you don't know what Object-Oriented Programming is, visit the blog post: What is OOP (Object-Oriented Programming)?

In order to understand what an object is in Object-Oriented Programming, let's start all the way down at the memory level. A single value of true is stored in memory as 1 whereas a single value of false is stored as 0 (alongside some metadata that informs of the value's type). Objects are containers (in the generic sense) that encapsulate 0 to N member variables. An attribute is one of two types of member variables. An attribute is a value that is associated to a name. The other is a method (just a function that is attached to an object).

How Are Objects Defined?
^

An object is defined in a class. A class is a blueprint for an object. It is a programming language construct that can be defined in many programming languages that offer this feature using the appropriate syntax. Only languages that offer Object-Oriented Programming features provide such syntax.

Languages Without OOP
^

In languages that don't support OOP or where OOP is not the primary paradigm (such as C or procedural programming aspects of various languages), object can refer to any data structure in memory, rather than an instance of a class. A simple boolean variable could even be considered an object.

General Computing
^

Outside of programming, object can refer to various entities, such as files, or even hardware devices that can be manipulated or managed by software. This can be generic definition could even be extended to refer to anything.

Software Design
^

Object can refer to any item in any diagram or design. In Object-Oriented Analysis and Design (OOAD), systems are conceptualized in terms of objects and their interactions.

Objects in Distributed Computing
^

Distributed Systems might use different programming languages in different microservices. An object in one microservice can traverse multiple services by serializing the object while it's in transit.

Protocol Buffers
^

One way to standardize object structure between services in a distributed system is using an interchange format like Protocol Buffers. Objects are defined in .proto files, and they can be built into objects in any language. Example:

syntax = "proto3";

package user;

// Message representing a user's information
message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
}

// Request message for creating a user
message CreateUserRequest {
  string name = 1;
  string email = 2;
}

// Request message for retrieving a user
message GetUserRequest {
  int32 id = 1;
}

// Response message for user operations
message UserResponse {
  User user = 1;
  bool success = 2;
  string errorMessage = 3; // Optional error message in case of failure
}

These objects are sent and received between clients and servers that are also defined in Protobufs, and are serialized in a very efficient byte-format. For example:

syntax = "proto3";

package user;

// Importing the message definitions from user.proto
import "user.proto";

// UserService provides operations on users
service UserService {
  // Creates a new user and returns the user details
  rpc CreateUser (CreateUserRequest) returns (UserResponse);

  // Retrieves a user by ID
  rpc GetUser (GetUserRequest) returns (UserResponse);
}

Above code snippets generated by ChatGPT.

Outside of Computer Science
^

Outside of Computer Science, object refers to practically any inanimate thing.

In the English language, object is the grammatical entity that is acted upon by the subject of a sentence.

Next Steps
^

Updated: 2024-03-04