Skip to content

Chapter 5: Object-Oriented Programming

Published: at 05:30 PM

Programmers were passing data structures into functions long before 1966, when Dahl and Nygaard moved the function call stack frame to the heap and invented OO. — Robert C. Martin

Object-Oriented Programming (OOP) defined as a means of modelling the real world in code does not give a clear picture and intricacies of OOP in real sense.

OOP supports:

Polymorphism is where OOP excels at the most — With the power of polymorphism, plugin architecture can be used anywhere, for anything.

Dependency Inversion uses polymorphism to achieve its goal. It involves:

  1. High-level modules depending on abstractions (interfaces or abstract classes)
  2. Low-level modules implementing these abstractions.

What can you do with that power? As an example, you can rearrange the source code dependencies of your system so that the database and the user interface (UI) depend on the business rules (Figure 5.3), rather than the other way around. — Robert C. Martin

From the above excerpt from Uncle Bob’s boo, it means that the codes for the business rules will never mention UI or database directly except through an abstraction (interface or abstract class), in this case, the dependency has been inverted.

In a nutshell, Uncle Bod in his ow term defines OOP this way:

OO is the ability, through the use of polymorphism, to gain absolute control over every source code dependency in the system. It allows the architect to create a plugin architecture, in which modules that contain high-level policies are independent of modules that contain low-level details. — Robert C. Martin