Basic programming, .NET technology.

Lập trình hướng đối tượng - OOP 1


If you are a student or a professional coder, you must have heard many times about OPP or object-oriented programming.
In my series of 2 articles, I will review the basic concepts of object-oriented programming. What is it? What are its characteristics?

OPP stands for Object oriented programming. It is a programming paradigm that is based on objects. It models real-world objects into programming objects. Those objects have the same properties and actions as in the real world. 

For example, A student is a real-world object. Student attributes height, weight, age, name... Actions: eat, sleep, walk, study. When modeled in programming, we also have an object that holds the data of student information and actions.
So each student object we create a student object in programming? It's not like that: We have concepts: object and class
What are classes?
It is a prototype of objects. It has variables that store data as well as methods of an object

We have a student class as follows


Object là gì?
Object là một thể hiện cụ thể của một đối tượng thực tế thông qua bản mẫu là một class. Khi một object được tạo thì nó sẽ được cấp phát một vùng nhớ trên heap để lưu trữ thông tin của nó.
Ví dụ: Ta có đối tượng sinh viên 1 là một thể hiện cụ thể của một sinh viên trong thực tế, qua bản mẫu là class sinh viên ta vừa tạo ở trên.

What are Objects?
The object is a concrete instance of an actual object through the template is a class. When an object is created, it will be allocated a memory area on the heap to store its information.

For example, We have student object 1 which is a specific instance of a student in reality, through the template is the student class we just created above.



Here we create a constructor with 2 variables passed in, name and age. This constructor will assign values to the member variables of the class.
When we initialize the student object with this constructor, we will pass the value of name, age.



Example: 

Using the student class creates a student object, and calls the object's self-introduction function.


Results: Just like in the real world, students use their own information to introduce others, in programming when abstracting an object, it also has the same behavior: using the information to self-identify. introduce yourself


Through this example, we can better understand: what is a class? What is an object? What is Constructor? And how to use them. In the following article, I will present the basic properties of OPP.

Related posts:
Share:

0 nhận xét:

Đăng nhận xét

Featured Posts

Data type 3 - string type