oops concept

Object-oriented programming (OOP) is a programming paradigm, founded on the principle of ‘objects’, which can contain both data and code. Within OOP, data takes the form of fields (AKA ‘properties’ or ‘attributes’), whereas code takes the form of procedures (AKA ‘methods’). 

This programming approach is supported to varying degrees within languages such as C++, Python, Java and more, and is used by developers to construct applications which can interact with one another. OOP is considered to consist of four central ‘pillars’. These are Abstraction, Encapsulation, Inheritance and Polymorphism.

Is OOP still relevant?

In Oslo, 1962, the Simula OOP language made its debut, fast becoming the go-to programming language for many developers. It is only in very recent years that the alternative approaches of functional and procedural programming paradigms have gained more momentum, posing a threat to the long-lasting dominance of OOP, and bringing its relevance into question. Recently, developers have been asking whether OOP is still useful, or if it has become redundant.

Paradigms and objects

In the context of software development, a paradigm is essentially a style of programming. Paradigms can be distinguished based on their specific structures, features and approaches to resolving different problems. Object-oriented programming is one such paradigm, which employs an arrangement of ‘objects’ to achieve the developer’s goals. 

Objects can be better understood alongside real life scenarios. For instance, in the case of a financial software application, some of the objects created by the developer might include ‘transactions’, ‘customers’ and ‘accounts’. This would enable the developer to break down the processes so that they can be understood and described in everyday terms.

This simplification facilitates better communication and more effective development, with software technicians able to discuss the processes of the application and describe them using domain-specific vocabulary. Other advantages of OOP’s object-centred approach include better traceability and more efficient maintenance.

The four pillars of OOP

By keeping in mind abstraction, encapsulation, inheritance and polymorphism whilst working, developers and programmers can create clean and effective OOP code. These are known as the ‘four pillars of object-oriented programming’.

Abstraction

Abstraction, in software development, means simplifying the user’s experience by only showing them the information that they need to see. Background processes are kept invisible, so as to provide a more concise, cleaner experience. Most users of software are unaware of the many background processes and mechanisms which are running when, for example, switching their laptop computer on. Abstraction in OOP includes the concealment of these underlying processes.

Encapsulation

Encapsulation in OOP relates to the process of combining methods and data into a single entity, thereby shielding the core operations of a particular object from external code. Encapsulation encapsulates various processes within objects, simplifying them and leading to cleaner, more organised code, which is easier to work with and understand. Another key benefit of encapsulation in OOP is that it provides added security, protecting the code within objects from unauthorised use.

Inheritance

The third pillar of object-oriented programming is inheritance. Inheritance, in this context, refers to the creation of code that will be reusable based on class hierarchies. This relates to the recycling and reuse of pre-existing code, and not to the upgrading or modification of it. These hierarchies consist of classes and, beneath them, subclasses, sometimes referred to as ‘parent and child’ classes.

Polymorphism

Code and data’s capacity to be processed in more than one form is referred to as polymorphism. By functioning in a polymorphic way, an object can simultaneously serve multiple purposes. Polymorphism enables different types of objects to be accessed through the same interface, which has a wide range of applications to developers.

Object-oriented vs. functional programming

Functional programming (FP), unlike OOP, takes a colder, more mathematical approach, treating elements of code as equations. This approach is efficient and effective, and it could be argued that FP makes the comprehension, testing and debugging of code even simpler. Even Agile’s Robert Martin has lauded this approach, suggesting that FP can produce safer solutions.

Both functional programming and object-oriented programming are paradigms which strive to create reliable, clean, error-free, robust and manageable code. So can FP really outperform OOP?

  • FP, unlike OOP, cannot arrange and store data in objects, making the use of writing functions a necessity.
  • OOP, however, does not easily allow for the maintenance of objects while increasing inheritance levels.
  • FP is more demanding, consuming more memory whilst running due to the fact that every function requires the execution of a new object.

Object-oriented vs. procedural programming

Procedural programming (PP), is another alternative to FP and OOP. PP is based on the notion of procedure calling. Within PP, procedures (AKA ‘routines’, ‘subroutines’ or ‘functions’) are sets of processes which are called and executed to completion. 

  • Procedural programming better reflects the real world, using processes which are given more weight than OOPs objects, the latter of which place more emphasis on data.
  • Procedural programming, however, is less easy to use when adding new data functions, whereas OOP makes this process much easier.
  • Inheritance is more easily achieved using OOP, which allows for the reuse of code, whereas PP does not support such a feature.

The verdict: OOP lives on!

The competition is stiff, and alternative programming paradigms have come a long way, perhaps even becoming effective enough to pose a legitimate threat to OOP. However, the vast majority of major programming languages are based on object-oriented principles. 

There are those who would argue that OOP has had its time, but there is no denying that it’s still very much alive and widely used by many. Furthermore, FP and OOP are not mutually exclusive; modern programming enables programs to be both at the same time. 

In the hands of a dedicated development team, OOP is an incredibly powerful tool, and one that is by no means ready to be succeeded, retired or replaced.