Hello dear readers of my blog! In this article, I want to clarify the purpose of the terms that we need to know when learning a programming language. That is, I want to try to explain in simple language the functions of terms such as object, class and methods in programming.
The reason is that many of those who are interested in programming and those who start learning are busy imagining the concepts of object, class, and method (function, etc. in some programming languages), and in this way, it becomes difficult to master programming.
But if we can see the parallels with real life and its bright examples, learning programming becomes a piece of cake.
ATTENTION ADVERTISEMENT! A video course on Java programming languages is ready. You can read information about the video course by clicking on the image below:
So, first of all, we will clarify how we should understand the object in the programming language.
We consider a car in life as an object in programming
To understand the object and its purpose, let's consider a simple analogy. Suppose you want to drive a car and you want to give it some speed by pressing the car pedal (gas). Now think, what must have happened before you did this?
Well, before you can drive a car, someone must have designed it, built it, and assigned it to the task you want it to perform.
Usually, building a car starts with engineering drawings, like blueprints depicting a home project. And these drawings include the blueprint for the car's pedal (gas). That pedal hides from the driver the complicated mechanism that increases the car's speed, and similarly the brake pedal hides the mechanism that slows and stops the car, and the steering wheel hides the mechanism that turns the car.
This allows people to easily control the car without knowing how the motors, braking, steering mechanisms work.
You can't drive the engineering blueprints of a car, just like you can't cook in the Andaza's kitchen. So, before you can drive the car, the car must be built based on the engineering drawings that describe it.
The finished car will have a pedal that gives the car speed. But this is not enough — the car does not move by itself. So the driver still needs to press the pedal to accelerate the car.
So, here is an object that a programmer should build in machine programming. And the driver is the user of the program.
Methods and classes
Let's use the machine example above to introduce some of the keys to object-oriented programming. Any program requires a method (function in C++) to perform a task. That method contains the statements that perform the tasks of the program. Just as a car's accelerator pedal hides the mechanism that accelerates the car from the driver, this method hides statements from the user of the program.
In the Java programming language, we create a program unit called a class, which contains a set of methods, and the methods perform the functions of that class.
For example, a class that represents a bank account number can include one method for depositing money into the account, another method for withdrawing money, and a third method for asking how much money is currently in the account.
In general, the class is similar to the goal in the engineering drawing of the car, that is, it is the home of the design of the accelerator pedal, steering wheel, etc.
Instantiation — creating an instance
Just as someone has to build a car before you can drive it, in order for a program to perform the tasks defined by the methods of a class, you must have created an object of that class. The process of doing this is called instantiation.
And then the object is referenced as an instance of its class.
Messages and method calls
When you drive a car, pressing its gas pedal sends a message to that car to do its job, which is to increase its speed. Similarly, you send a message to an object.
Each message is implemented in a method call that tells the object's method to perform its task. For example, a program can call the deposit method of the bank account number object to increase the amount of the account number.
The above are some of the basic concepts of programming, and these are the parts of programming that we want to cover in this article. I would like to say this at the end of the article, read the article closely and if you have any comments, leave them in the comments!
If you want more specific coverage of programming or any similar topic leave it in the comments!
See you now, goodbye!