Answer the question
In order to leave comments, you need to log in
How are Classes different from normal functions?
I have written a couple of progs using classes and this arhi is handy! But, I don't quite understand the division into classes, objects, functions, operators and data types. After all, in fact, all these are data structures and operations on them. After all, if you can be clever, using a class, write analogues of cycles, conditional operators, and other things, since when you call an operator, this is after all an object that the language developers added, you can go into the config and cheat with the same operators. Or I don't understand something!? I have a mess in my head from the abundance of terms, help me clean it up a bit. In Haskell, for example, there is no if, for, there are only functions!
Answer the question
In order to leave comments, you need to log in
Grady Booch Object Oriented Analysis and Design Free Download
OOP is not complexity management, as many will write here. This is the essence of another level of abstraction. You have mixed entities from different levels into one heap.
Look - in the physical world there is a microworld with electrons, protons, photons, and I don't know what else. It works according to its own laws of quantum mechanics. There is a macrocosm of the level of things of planes, apples, trees. It works according to the laws of Newtonian mechanics. There is a world of cosmogony at the level of stars of galaxies of black holes. He works on Einstein's Theories. See how simple. We have gone through three levels of abstraction of the material world from the lowest to the highest.
Similarly, in the world of information, there are the lowest levels of machine codes, registers, and individual bits. And there are higher levels of functions, even higher levels of classes, and even higher levels of abstraction. So your task is to sort all those entities that you brought correctly into different levels. And you have everything in one heap: operators, variables, classes. And the upper world does not need to know anything about the lower. Then everything will be right.
The trouble with programming is that very powerful tools are available to everyone. Imagine a medical laboratory with microscopes, scalpels, test tubes and other equipment. Not everyone will be allowed in. In programming, everyone can click the download button and start doing all sorts of garbage. Sew the fifth leg to the dog, grow an ear on its back and horns on its forehead. There was such a book - "The Tiered World". There, one comrade specialized in such freaks. Then these freaks begin to take revenge on their creator.
So a normal programmer, once in this world of freaks, often falls into a stupor. Why do this? Well, you can do whatever you want. But not necessary. Its task is to reduce the entropy of the universe, not increase it.
Let's take C++. It has basic data types (int - a type for integers; float and double - types for fractional numbers, bool - a type for storing a logical value) and basic operators (+, -, *, / - for creating expressions with arithmetic operations; ||(or), &&(and), !(not) - for expressions with logical operations; ==, !=, >, <, <=, >= - for expressions with comparison, = - assignment operator that calculates a value expression and storing it in a variable.There are also statements that control the course of the program execution (loops - for, while, do..while; program branching - if..else, switch).By creating variables to store values of basic types, and descriptions sequence of execution of basic statements on these variables, you can write any program, but it can turn out to be long and confusing. For a local record, a grouping of basic elements into custom composite elements is used. These are user-defined data types (for variables) - structures and classes; and custom operators - functions. After the user describes their own types and their own functions, they can be used in the program on a par with the basic ones.
If you take JavaScript, then everything is very similar. The difference is that you do not need to warn the compiler (which does not exist, but there is an interpreter) in advance about the type of variables. Variables are rubber and store everything that they put in them. Whether it's a value of a base type or a custom one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question