Monday , 28 September 2020
Breaking News

Object Oriented Programming Concept in C++


Notice: Undefined index: tie_hide_meta in /home1/adnanonl/public_html/wp-content/themes/sahifa/framework/parts/meta-post.php on line 3

Notice: Trying to access array offset on value of type null in /home1/adnanonl/public_html/wp-content/themes/sahifa/framework/parts/meta-post.php on line 3
Spread the love

Object Oriented Programming (OOP) is a special way of programming, closer to how we would express things in real life than other types of programming.

With the OOP we have to learn to think things in a different way, to write our programs in terms of object s, properties, methods and other things that we will quickly see to clarify concepts and give a small base that allows us to let go a little with this type of programming.

Motivation
For years, programmers have been dedicated to building similar applications that solve the same problems over and over again. In order to get the efforts of the programmers to be used by other people, the OOP was created. That is a series of rules of doing things so that other people can use them and advance their work, so that we get the code can be reused.

The OOP is not difficult, but it is a special way of thinking, sometimes subjective of the programmer, so that the way of doing things can be different according to the programmer. Although we can do the programs in different ways, not all of them are correct, the difficult thing is not to program oriented to objects but to program well. Programming well is important because we can take advantage of all the advantages of OOP.

How do you think about objects
Thinking in terms of objects is very similar to how we would do it in real life. For example, we are going to think of a car to try to model it in a POO scheme. We would say that the car is the main element that has a series of characteristics, such as color, model or brand. It also has a series of associated features, such as start-up, stop or park.

For in a OOP scheme the car would be the object, the properties would be the characteristics such as the color or the model and the methods would be the associated functionalities such as starting or stopping.

To give another example we will see how we would model a fraction in a OOP scheme, that is, that mathematical structure that has a numerator and a denominator that divides the numerator, for example 3/2.

The fraction will be the object and will have two properties, the numerator and the denominator. Then you could have several methods like simplify, add with another fraction or number, subtract with another fraction, etc.

These objects can be used in the programs, for example in a mathematics program you will use fraction objects and in a program that manages a car workshop you will use car objects. Object-oriented programs use many objects to perform the actions they want to perform and they are objects themselves. That is to say, the car workshop will be an object that will use car objects, tools, mechanics, spare parts, etc.

OOPS classes
Classes are declarations of objects, they could also be defined as object abstractions. This means that the definition of an object is the class. When we program an object and define its characteristics and functionalities, what we are really doing is programming a class. In the previous examples we actually talked about the car or fraction classes because we were only defining, although above, their forms.

Properties in classes
The properties or attributes are the characteristics of the objects. When we define a property we usually specify its name and its type. We can make the idea that properties are something like variables where we store data related to objects.

Methods in the classes
They are the functionalities associated with the objects. When we are programming the classes we call them methods. The methods are like functions that are associated with an object.

Objects in OOPS
The objects are examples of any class. When we create an instance we have to specify the class from which it will be created. This action of creating an object from a class is called instant (which comes from a bad translation of the word instace, which means exemplary in English). For example, an object of the fraction class is for example 3/5. The concept or definition of fraction would be the class, but when we are talking about a specific fraction 4/7, 8/1000 or any other, we call it an object.

To create an object you have to write a special instruction that may be different depending on the programming language that is used, but it will be something similar to this.

miCoche = new Car ()

With the word new we specify that you have to create an instance of the class that follows next. Within the parentheses we could place parameters with which to initialize the object of the car class.

 

watch, learn and share this information with your friends and family members.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *