What is an object oriented concept

Object-oriented programming - simply explained!

In this article I would like to explain to you in detail and in an easily understandable manner what is called the object-oriented programming understands.

Especially as a programming beginner, when you are still looking for a suitable programming language for yourself, you hear the term object-oriented programming very often, but you don't know what to do with it. I, too, had the concept of object-oriented programming when I first started programming not really understood and had to give me the knowledge for this laborious search together.

However, I would like to make it much easier for you to understand and penetrate the concept, and you simply have to do this just read this article.

What is Object Oriented Programming?

Object-oriented programming (OOP for short) is a so-called Programming paradigm. The word paradigm is not used that often in everyday language, which is why I would like to briefly translate it into a simpler language for you. Programming paradigm translated means nothing else than Programming style. Object-oriented programming is therefore a Way of thinkingthat you have as a programmer when you program with an object-oriented language such as C # or Java.

Because the object orientation to the very similar to human thinking, this programming style can be done by a human programmer too used very intuitively become. So it is an easy concept for humans to understand and use because it is based on our natural human thinking.

Object oriented programming concept

So let's take a closer look at this concept. Everything in object-oriented programming is done through what are known as Objects pictured. So every “part” that exists in a program becomes described by an object.

So that the whole thing does not remain so abstract, let's illustrate the concept directly with an example:

Suppose you want to program a game in which there is, among other things, a dog walking around in this game world. If you want to implement this scenario with an object-oriented programming language, so the dog is nothing more than an object.

Let us now go back to reality and consider how humans perceive a dog in reality. The majority would now say that humans perceive a dog as an animal or a living being. That is perfectly true, of course, but on one even higher level of abstraction, even in reality a dog is nothing other than a for the human mind object in the big wide world. Trees, cars, tables and other people are just the same, nothing more than objects.

In short, objects are all physically imaginable things that exist in our space.

And it's the same in object-oriented programming. All imaginable things that exist in the program will described by objects. If a dog is to be depicted in a game, it is embodied by its own dog object. If you want to represent a person in a game, this person is embodied by a human object. A house is represented by a house object and so on. I think that the basic approach of object orientation should now have become clear to you.

So the principle of object-oriented programming is:

Everything is described by individual separate objects.

(NOTE: Are you a complete novice to programming and do not yet know 100% which programming language to start with? Then secure our video series for beginners for FREE now! In this video series you will learn what a programming language is, which programming languages ​​actually exist and which one you should ideally start with as a beginner. Get the series here.)

Since the general concept has now been explained in detail, we can go into more detail below and look at the Construction of objects look at.

Every object has so-called properties (sometimes called Attributes designated). These properties are used to describe the object.

Let's take up the example with the computer game from before. We now assume that in addition to the dog from before, in the game world, there is also several houses should stand. Each of these houses is then logically back through a extra house object shown. If there are 20 houses in the game world, there are 20 individual house objects.

Each of these houses now has a number of propertiesthat the respective house describe. Let's assume that a house object has the following properties:

The house then has it in our play world 8 rooms, 10 windows, is blue has been crossed built in 1990 and the owner is John Doe. These properties now relate to this one very specific house object.

The second house in the game world is now described by another house object. This also has the same properties again, but these are now assigned their own values ​​that describe House 2 accordingly:

The second house then has it in the game world 6 rooms, 9 windows, is green has been crossed built in 1945 and the owner is Peter Müller.

And so you could now describe the remaining 18 houses in our game world with the help of your own objects and corresponding properties. By the way, you can create as many house objects as you want, as long as you have the necessary memory available.

Objects now not only have the properties just presented, but also so-called properties Methods (Functions). With the help of these methods, the objects can have certain Execute functionalitieswhich makes a lot of sense, because otherwise all objects would be very boring, could not do anything and would just exist.

In addition to the properties, methods now also provide functionality to the objects.

A house object could for example be the heat () method have. As soon as this method is carried out, the heating of the house could be activated and activated, for example. Also one alarm () method it would be conceivable that the alarm system of the house would be activated in the event of potential break-ins. So you see, objects can numerous methods own which meaningful functionality to implement.

A method thus contains code through which a functionality is implemented.

So let's finally summarize the structure of objects again. An object is a physical "something" within a program that described by properties becomes. In addition, objects can also Functionality own which expressed by methods become.

Since you now know both the concept of object-oriented programming and the structure of objects, I would now like to turn to the so-called Classes come to speak. If you are working with an object-oriented language, then you will inevitably always confronted with classes become. But what are classes actually?

Classes are blueprints for objects.

Let us illustrate this using the house objects from the previous example. Each of these objects had the same number and type of properties, but all of them were assigned different values. For example, there was the “color” property, which was assigned the value “blue” for house object 1 and the value “green” for house object 2.

It is no coincidence that the number and type of properties were the same for each of the house objects, because all house objects have the are based on the same blueprint. And this blueprint is used in programming as a class designated.

The class thus implements the various properties that one or more objects of the type of the class should later have. Every object that we then create within our code on the basis of this blueprint has the properties specified in the class. Which concrete values ​​the properties have depends on the object.

Classes specify the basic structure of an object with their properties and methods and you use them to define your own types.

So let's summarize the whole thing again briefly:

Before you can create house-type objects in a program, you have to first of all define the class house. With this, the construction plan for the later house objects is given. In this class, you do not specify any values, but rather just the properties and methodsthat a house object should own later. Only when you then specifically create an object from this class, you assign its properties concrete values.

The methods are also used in the same way initially defined in the class. All objects that we then create from the class automatically have these methods and can also call them.

Additive: Classes can reused become. If, for example, we include the house class in our current program independentlyfrom other classesdevelop, then we could house this class in a completely different project reuse. So you can reuse code that you have written once.

There is one more thing in object-oriented programming very important and extremely useful concept, namely that Concept of inheritance. First of all: This makes the programming of object-oriented programs greatly relieved.

In object-oriented programming it is possible to To inherit classes. In inheritance takes over a class all properties and methods another class. This allows you to have a extend an already existing classwithout this class change afterwards to have to.

Let's take a look at the concept with a small example:

We define a class for our program called Mammal. The class has two properties, namely the name of the mammal and the gender of the mammal. In addition, every mammal also has two methods, namely eating () and drinking ().

With this class we could already create objects of the mammal type. In many cases, however, it would no sense because if we want to create an object, we usually do one more specific, namely a concrete mammal like a cat or a dog.

For this reason one is now defining one for both the cat and the dog extra classand then inherits it from the Mammal class.

This ensures that the Basic characteristics of all mammals, already defined in the mammal class become. The more specific class dog inherits all of these basic properties then from the mammal class, adding properties and methods specific to the dog.

For example, a dog can bark, which is why it is given a extra method should provide. All you have to do is define the method bark () in the dog class. The code for the basic properties is inherited and must therefore Not more to be written in the dog class.

If you only need objects of the dog type, you could of course also define the basic properties directly in the dog class and then do without the mammal upper class. But as soon as you define several mammals, the whole thing makes sense. Because if we now also define a class cat, for example, we can also have this inherited from the class mammal, and only have to define the properties and methods specific to cats.

So we have two classes defined (Dog, cat) and only had to write the code for the basic properties ONCE. If you now need 20 different mammals, you save yourself having to write the same code 20 times.

So inheritance is a concept to extend classes. This simplifies programming because code does not have to be rewritten repeatedly and certain levels of abstraction can be introduced.

(NOTE: Are you a complete novice to programming and do not yet know 100% which programming language to start with? Then secure our video series for beginners for FREE now! In this video series you will learn what a programming language is, which programming languages ​​actually exist and which one you should ideally start with as a beginner. Get the series here.)