Posts

Showing posts from July, 2020

What is "polymorphism" in OOP

Image
Polymorphism is the property of a system to use objects with the same interface without information about the type and internal structure of the object. The advantage of polymorphism is that it helps reduce program complexity by allowing the same interface to be used to define a single set of actions. The choice of a specific action, depending on the situation, rests with the compiler of the programming language. Hence the key feature of polymorphism is the use of an object of a derived class, instead of an object of the base class (descendants can change their parent behavior, even if they are accessed by reference of the parent type). Any training in driving would not make sense if a person who learned to drive, say, a VAZ 2106 could not then drive a VAZ 2110 or BMW X3. On the other hand, it is difficult to imagine a person who could normally drive a car in which the gas pedal is to the left of the brake pedal, and instead of the steering wheel there is a joystick. The thing is t...

What is "inheritance" in OOP

Image
Inheritance is a property of the system that allows you to describe a new class based on an existing one with partially or completely borrowed functionality. The class from which inheritance is made is called ancestor, base or parent. The new class is a descendant, inheritor, or derived class. Let's imagine ourselves, for a moment, engineers of an automobile plant. Our task is to develop a modern car. We already have a previous model that has proven itself over the years. Everything would be fine, but times and technologies are changing, and our modern plant should strive to improve the convenience and comfort of products and meet modern standards. We need to make a whole range of cars: sedan, station wagon and subcompact hatchback. Obviously, we are not going to design a new car from scratch, but, taking the previous generation as a basis, we will make a number of design changes. For example, let's add power steering and reduce the gaps between the fenders and the hood lid...

What is "encapsulation"

Image
Encapsulation is a property of the system that allows you to combine data and methods that work with it in a class and hide implementation details from the user, revealing only what is needed for subsequent use. The goal of encapsulation is to get away from the implementation dependency of the external interface of a class (something that other classes can use). So that the slightest change in the class does not entail a change in the external behavior of the class. Let's imagine for a moment that we found ourselves at the end of the century before last, when Henry Ford had not yet invented the conveyor belt, and the first attempts to create a car faced criticism from the authorities that these smoking monsters pollute the air and scare horses. Imagine that in order to drive the first steam car, it was necessary to know how the steam boiler works, constantly toss up coal, monitor the temperature and water level. In this case, to turn the wheels, use two levers, each of which tur...

Basic principles of OOP

Image
Basic principles of object-oriented programming (OOP) are follows: Encapsulation is implementation hiding. Inheritance is the creation of a new entity based on an existing one. Polymorphism is the ability to have different forms for the same entity. Abstraction is a set of common characteristics. Sending messages is a form of communication, interaction between entities. Reuse - everything listed above works for code reuse. This is the only correct order of OOP paradigms, since each subsequent one uses the previous ones. Read also: What is object-oriented programming

What is object-oriented programming

Image
Object-oriented programming (OOP) is a programming methodology based on representing a program as a collection of objects, each of which is an instance of a certain class, and the classes form a hierarchy of inheritance. Object Oriented Programming uses objects rather than algorithms as the main logical building blocks; every object is an instance of a certain class classes form hierarchies. A program is considered object-oriented only if all three of these requirements are met. In particular, programming that does not use inheritance is called programming using abstract data types, rather than object-oriented. According to the OOP paradigm, a program consists of objects that exchange messages. Objects can have state, the only way to change the state of an object is to send it a message, in response to which the object can change its own state.