The principles of object-oriented programmingOOP has three basic principles:
- Inheritance
- Encapsulation
- Polymorphism
Inheritance can be compared to cloning. This principle is the essence of the relationship between classes and objects. It means that each child "clone" inherits the attributes and methods given in the parent element: it can take all of them, drop some, or add new ones. In this case, you do not need to specify the same data many times.
Encapsulation. This is where you store the data needed to make the object work. Foreign objects and classes cannot modify it. Only public attributes and methods are available to them. This principle protects the data of an object or class from damage by outsiders.
Polymorphism is a redefinition of behaviour. The same method can work in different ways. For example, the parent class "person" can move, the child objects "driver" and "pedestrian" can do the same, but in different ways: one in a car, the other on foot.
Advantages and disadvantages of OOPThe advantages of object-oriented programming are:
- It is more convenient to write code with objects. Easier to write code with classes or methods. In addition, it can be easily transferred to other projects.
- Code is much easier to read, even by someone else.
- Easy to update. Just change a class or method in one place, and everything in the inherited element changes.
- Good scalability. Thanks to the independent modular architecture, different developers are responsible for different modules of the program.
The disadvantages, according to BizUPLab Budapest experts, are:
- Difficult to learn.
- The worst performance. Objects consume more memory than programs without OOP. This also applies to the compilation speed.
- The amount of code is higher than in procedural programming. This is a plus when the structure of large programs becomes clear, but for small software products it is a waste of time.