what are objects

An elementary class of introduction to object-oriented programming in which concepts such as object, class, method, property, state or message are clarified, knowing the OOP syntax in Javascript.

This class offered an introduction to objects in the context of programming and Object Oriented Programming (OOP) in general. It was given by Miguel Angel Alvarez, founder of .com and EscuelaIT.

Object-oriented programming is a somewhat advanced topic and perhaps in what we are giving it is a bit ambitious to want to deal with it in detail. However, today most languages ​​are object oriented and in almost all of them we have to work with objects to achieve our goals. That’s why we’ve added this class.

The objective, therefore, is to explain the fundamental concepts related to objects, so that they are familiar to us and we can understand the bases of this programming model, present in Javascript, but also in many other popular languages.

This is a class that requires a special effort, to open your mind and assimilate slightly more abstract concepts. That is why I ask you for a little patience and although at first concepts may seem complicated, you will observe that little by little you will understand better what this object thing is about.

Below you have a text summary of the content of this class and at the end you will find the complete video of this class embedded, where this information is expanded, along with the slides.

Note: We have decided to divide the class of objects into two videos, in this one you have general knowledge of objects and in the next one you will see how to apply that knowledge to Javascript, explaining the syntax of objects in that language and examples.

What is an object?

Luis Fernández defined it when he told us about: Heterogeneous groups of simple data, with their operations.

Perhaps at the moment it is a bit difficult to assimilate the world of objects through that definition, but throughout the class it will be explained in more detail and you will be able to understand the phrase.

What is Object Oriented Programming?

In this class we begin by clarifying what Object Oriented Programming is. The objective is more to see what the objects themselves are, but it is interesting to know where they come from.

Object Oriented Programming is a programming paradigm in which, as in real life, a universe of objects collaborate to carry out actions.

Ex: human. Any of us could be decomposed into a series of objects, which form systems and collaborate with each other to carry out a human life. In the OOP an attempt is made to bring this same scheme to software development, which is repeated both in nature and in the structures or systems created by us.

See also  Send an array of input elements in a form with PHP

Formally, an Object in the framework of the OOP / OOP is a specific instance, a unit of something whose characteristics have been defined in a class.

As you can see, none of these definitions we are still able to assimilate 100% and, much less do they make us understand what these objects are. So we will have to go back a little further to be able to give a definition that we are able to understand.

At the beginning of computers, everything was zeros and ones.

Today too, but we have long passed that stage and for you as a programmer to know that inside there are all zeros and ones it should not be more than a mere curiosity. But imagine a time when programmers had to express algorithms in zeros and ones…

Assembly language quickly arrived:

Fortunately for the programmers of that time it passed quickly and most never had to face building a program with only zeros and ones. Instead, languages ​​like assembler are used. This language provides us with very low-level instructions with which to perform very, very basic operations at the hardware level.

High-level languages ​​and Javascript:

Before the advent of Javascript there are several intermediate steps, but you notice that with Javascript it is easier to program than with zeros and ones or with assembly language. This is because every day languages ​​are more like the way people express themselves. These types of languages ​​less close to the machine and more to the expression of humans are called high-level languages.

Why do you think languages ​​evolve?

To make it easier for the programmer to solve the needs, expressing algorithms in a language closer to the spoken or written language, which we already know perfectly.

Object Oriented Languages

In the evolution of programming languages, for various reasons that would take too long to explain, object-oriented languages ​​improve the way algorithms are expressed. These languages ​​are capable of higher levels of abstraction, modularity, and hierarchization, which are desirable characteristics of any program. In short, what you have to stay with now is that through OOP programmers can make more complex programs in an easier way. And not only that, it also allows us easier maintenance, which always results in lower costs in software development, better-made programs and capable of doing more complex things.

One of the many things that evolved in languages ​​has to do with data types.

Data types in the evolution of languages

As you will remember, the data types in Javascript are:

  • Numeric
  • String
  • logical (boolean)

With these data types, which are the main ones in most languages, they are called primitives. Anything is built on them, an exciting car racing game is made, “a rocket is taken to the moon”…

See also  The RecordSet Object

But what about the more complex data types? For example, think of a coordinate on the 2D axis. The coordinate is defined by two values ​​(x,y).

If you want them to go together you can use an array structure, a variable with multiple compartments to store things. Like the folders with compartments where you keep the notes for each subject separately. We will see solutions like these for arrays in the class dedicated to data structures.

A coordinate is made up of two numbers (numeric data type elements), but in practice, we often want to put different things together.

heterogeneous groupings

Think of things like these, which have to be handled in a multitude of programs:

    Invoice:

  • numeric for the invoice number.
  • string for customer name
  • Boolean to say if it is paid or not…

    User:

  • numeric for user_id
  • string for your name
  • Boolean to say if you have your email verified

You will notice that in these, and many other elements of the programs, you need to mix different things. We could use an array, but you will soon see that it falls short and what is worse, in many languages ​​you cannot put things of different types in the same array. That is, if you make an array in C, all the elements of that array must have the same type.

There is not only data, there are also operations

Now, languages ​​don’t just allow you to work with data. What’s more, programs make sense when they allow operations with that data. So, you will notice that on the other hand we have the functions.

We return to the coordinate. Within a program you may want to do things with the coordinate:

  • Subtract or add another coordinate
  • Translate it on the x-axis or on the y-axis
  • With two coordinates you may want to know the distance that separates them

All those functions, with what you know now, have to be defined separately. That is to say, in the languages ​​we have on the one hand the data, in variables or structures, and on the other we have the functions. Perhaps today you are still not able to see the problem of it or the way to improve this situation, but many thinking people have come up with solutions. So that you can see it, it may be good to carry out an analysis.

Consider that you want to know the distance of two points (this algorithm was explained in ).

function distance_two_points(ax, ay, bx, by){ //Calculate horizontal component //Calculate vertical component //I square the components //I add them //I apply the square root //I return the result }

See also  What is a citation in APA format

What would you think if you could also ask a coordinate (which we initially said were two pieces of data with two points, on the x and y axis) to perform operations? In that case you could solve that operation of requesting the distance simply by asking the coordinate to indicate it to you.

“Cooordinate, please give me the distance with another_coordinate”

When we have heterogeneous data structures such as an invoice, or a user, it is extremely useful for us to include a series of associated functionalities within them, because it greatly simplifies working with them.

invoice, apart from simply saving that data, I also find it convenient that it responds to the things I need to do about an invoice:

  • record payment
  • calculate price without VAT
  • calculate price with vat
  • Add a new product to the invoice
  • to print
  • Pay invoice in case of return

It would be very useful for a user if he could perform operations such as:

  • Check if it is valid
  • open or close session
  • unsubscribe

All this facilitates programming, simplifies the code and allows greater reuse and modularity. I summarize some details.

I define the invoices once and then I can create as many as I want, all of them will have the data of each invoice of my program and they will respond to the usual operations that I need.

In my management program, which works with invoices, I simply ask the invoices to do things, please invoice, print, subscribe, tell me your price without VAT…

I am able to reuse the code from my invoices for any management program that has to work with invoices.

Let’s go back to object definitions

With what you already know, we are now able to take again those phrases that were used to define an object:

Heterogeneous groups of simple data, with their operations.

It is an instance of an element type, made up of a series of data that defines it, together with a series of operations that you could do with this element type.

Terminology when working with objects

As of what we’ve seen at this point in the class summary we’ve more or less covered the first 15 minutes of class. There is actually a lot more information, since so far the reasons why object-oriented programming exists have only been explained a little.

In the presentation, object-oriented programming was addressed from a more academic point of view, defining each of the members in this paradigm.

  • Class
  • Object
  • Property
  • Method

In…

Loading Facebook Comments ...
Loading Disqus Comments ...