What is the object and how orient to it
As is well known almost all programming languages in the world today are object oriented languages. But what does it mean? What is an object? What object do they mean? And to orient on it?
What is the meaning of the notion object-oriented? According to Wikipedia: Object-oriented programming (OOP) – programming paradigm, in which the basic concepts are the concepts of objects and classes.
For a better understanding let’s turn to my favorite allegories. Imagine what we are doing cookies – gingerbread men. Our entire program logic – is the stretched almost ready dough. Now we need to select the objects, that is to make each individual cookie. Everyone knows that the ginger man should have 2 feet, two hands, eyes, smile, and buttons. In prototyping languages the logic is that each programmer sculpts a gingerbread man itself. And he may himself each time for each new gingerbread man make his own design. Adding buttons or not? To make a man having two eyes, or make it like Cyclops? J
In general, each time you create a new object it is not necessarily follow the specified earlier style. You can add or remove properties or methods. In the second example of the code you will notice that Cyclops has no buttons, and he does not speak words of welcome.
In ordinary programming there is a more clear-cut. That is, every time you create an object it is necessary to create it as an example shown in the class. It is necessary to use a form for each person, that is, he definitely must have legs, arms, buttons etc. If provided in the “form” – i.e. the class of the man will speak words of welcome. That is, in fact there is no choice. If we want to make Cyclops without buttons and a welcome speech in C # for example, then we will have to create a new class – the “Cyclops” and in it – our object – cyclops Pretty.
This is the code in C # to create a class Gingerbread man:
This is the code to create an object gingerbread man named Happy and indications of its working function when he greets you:
This is the code to create the class Cyclops:
This is the code to create an object cyclops called Pretty:
As you can see, to create a new object in C # only 1 line of code is needed. This is the main advantage of ordinary object-oriented languages. That means that you can create a huge number of identical objects with less code.
I hope this view is understandable. If not, I’m ready to explain my vision in the comments.