Object-oriented programming or OOP is programming model based on the concepts of "objects", which are data structures that contain data, in the form of fields, and code, in the form of methods. In addition, programmers can create relationships between objects. For example, objects can inherit data and methods from other objects. Program, designed with OOP approach, is maked of objects that interact with one another. Most popular languages have class-based OOP, meaning that objects are instances of classes, which typically also determines their type.
In past, prevalent programming paradigm was functional programming. It is quite different from OOP, since it is based around evaluation of functions and avoids changing state of application and usage of mutable data. In functional code, the output value of a function depends only on the arguments that are input to the function. In opposite, OOP is based on objects, their state and data. Nowadays, functional programming considered deprecated in most cases, it is used mainly in mathematical applications when a lot of calculations should be performed.
Fundamental OOP concepts
There are four fundamental OOP concepts, which makes OOP approach as powerful as it is.
- Inheritance. This allows classes to be arranged in a hierarchy that represents "is-a-type-of" relationships. Child class derives functionality of its parent. This is powerful tool of code reuse.
- Polymorphism. This might be complicated to understand at first, but basically polymorphism is ability to provide access to entities of different types through single interface. The basic goal of polymorphism is to make applications more modular and extensible.
- Abstraction. Abstraction is simplifying complex reality by modelling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.
- Encapsulation. Encapsulation is a strategy used as part of abstraction. Encapsulation refers to the state of objects - objects encapsulate their state and hide it from the outside; outside users of the class interact with it through its methods, but cannot access the classes state directly.
- Object-oriented programming (OOP) is programming model based on the concepts of "classes" and "objects" and relationships between them.
- OOP is more modern programming paradigm than functional programming and is most wide spread nowadays.
- There are four main concepts in OOP: inheritance, polymorphism, abstraction and encapsulation.