Benefits of object-oriented programming

Old programming languages, such as Assembly or FORTRAN, are not object-oriented languages. Instead, these are procedural programming languages, languages in which a program is written in one long procedure. The data and the logic are coupled together in one place and a program contains a list of routines or subroutines to instruct the computer step by step. This approach is also known as a top-down approach, because instructions are executed one after the other. Procedural programming comes with a number of drawbacks:

  • There is no information-hiding mechanism; data is exposed to the whole system
  • Data and functions are stored in separate memory locations
  • It is difficult to map real-world objects
  • The code cannot be reused; each module or instruction set requires its own tightly coupled routine
  • The code cannot be extended; it is difficult to create a new data type using an existing module
  • A change in one function may affect the rest of the application

Procedural programming does, however, have the following benefits:

  • It is relatively simple and easy to implement functions and procedures
  • It is easy to keep track of the program flow
  • The application contains less complex logic

In object-oriented programming, the procedural code is divided into self-contained modules, called objects. In this form of programming, the focus is not on structures, but on modeling the objects. Each object represents a different part of the application and each object contains its own properties and functions in one place. An object is a complete entity and it does not rely on other objects. We will learn more about object-oriented programming and its implementations throughout this chapter, but first, let's have a look at some of its benefits:

  • Data is completely hidden and protected from other parts of the application. This is known as encapsulation.
  • Data can be exposed on request.
  • The code can be reused and extended, which means you can create new data types. This is known as inheritance.
  • Objects can behave differently in different situations. This is known as polymorphism.
  • Data and functions are stored in one memory location.
  • Object-oriented programming allows us to map different objects with which we are already familiar, such as person, bank account, car, and employee. 
  • Design patterns are based on object-oriented programming techniques.

Object-oriented programming has the following disadvantages:

  • It has complex logic, so it requires more work to design well-structured architecture
  • The complexity of the programming makes it difficult to find bugs
  • It requires more memory space
  • It is slower than procedural programming

Object-oriented programming is the best approach out of the available programming paradigms. Throughout this book, we will learn about classes, polymorphism, inheritance, and other concepts that are directly related to object-oriented programming techniques and design patterns.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.184.200