Escriu per cercar…

Object

An object is a data structure (state) with a set of functions specific to the object that give a different result depending on the state of the object (its attributes).

Aquesta pàgina encara no s'ha traduït — es mostra en l'idioma original:English

Introduction

Object-oriented programming was born with Simula in 1962, and its origin is to simulate objects and interactions between objects.

An object is a data structure (state) with a set of functions specific to the object that give a different result depending on the state of the object (its attributes).

Finally, remember that object-oriented programming is invaluable in creating user interfaces, real object simulation programs (such as 3D design), etc., but not in managing processes that process data such as artificial intelligence, web services, etc.

Object

Data structure

Every programming language is composed of simple data structures that allow you to represent anything, for example, a rectangle:

python
rectangle_length = 3
rectangle_width = 6

But if we have two rectangles, how can we represent them?

python
rectangle_a_length = 3
rectangle_a_width = 6

rectangle_b_length = 5
rectangle_b_width = 10

It’s not a good solution. What if we use a list?

python
rectangle_a = [3, 6]
rectangle_b = [5, 10]

In this way, we have the properties of a rectangle grouped in a single data structure under a single reference.

Functions

What if we want to calculate the area of a rectangle?

python
def rectangle_area(length, width):
    return length * width

def test():
    assert rectangle_area(3, 4) == 12

Estàs llegint una vista prèvia.

Inicia sessió per llegir l'article complet. Qualsevol compte obre 4 articles gratuïts al mes; l'alumnat i el professorat llegeixen les pàgines del seu curs sense límit.

Inicia sessió