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).

S'ensenya a
Llenguatges de marques i sistemes de gestió d’informacióDocuments dinàmicsASIXProgramacióProgramació orientada a objectesDAW-BIOProgramació orientada a objectesClasses, objectes i herènciaPYTHON

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ó amb Google per llegir la pàgina completa.

Inicia sessió amb Google

Amb qualsevol compte de Google. Només et demanarem que acceptis les condicions del servei.