We look at coding that puts the focus on objects rather than actions
Object-oriented programming (OOP) is a method of programming built around objects rather than procedures.
Before this model came to the fore, programs were more like a procedure where data is inputted, processed, and the output data produced. Procedural languages need you to think terms of a computer rather than the problem needing to be solved.
While this is useful for less complicated applications, the lack of objects can make it difficult for programmers to analyse code. Reusable components can also lead to greater efficiency and simplified programming.
Concepts of OOP
At the core of object-oriented programming are the objects themselves. These objects are arranged into classes, which allow individual objects to be grouped together. These objects interact with each other. With the objects given attributes and behaviours, developers can set these aside to concentrate on programming how these objects interact with each other.
When one object acquires all the properties and behaviours of parent object this is known as inheritance. A class that is used as the basis for inheritance is named a superclass. A class that inherits from a superclass is named a subclass or derived class. Parent class and child class are also acceptable terms. Inheritance gives OOP code reusability and is used to achieve runtime polymorphism.
Polymorphism is where a single task can be performed in multiple ways. This means OOP has the capacity to select the exact called function at runtime depending on the current context. There are two types of polymorphism; overriding and overloading. Overriding (run-time polymorphism) is where two methods have the same method name and parameters (i.e. method signature). One method is in the parent class and the other is in the child class. Overloading (compile-time polymorphism) happens when two or more methods in one class have the same method name but different parameters.
Abstraction is where a programmer can conceal everything except the relevant data about an object in order to decrease complexity and increase efficiency. In other words, representing features without including background details or explanations.
Encapsulation is a concept where data and methods that work on that data are bundled together in one unit. It’s used to conceal values or state of a structured data object inside a class, preventing unauthorised direct access to them.
Abstraction and encapsulation may sound similar, but the two differ in that abstraction hides unwanted details while giving out most essential details, while encapsulation means hiding the code and data into a single unit.
Examples of object-oriented programming languages
There are many different languages that use object-oriented programming. Among them are Java (which was developed in 1995 by Sun Microsystems, now Oracle), Python (created in 1991 and emphasises code readability), C++ (which has imperative, object-oriented and generic programming features and is an extension of the C programming language), and Objective-C (which adds Smalltalk-style messaging to C and was the main programming language for OSX and iOS).