Home > Net >  What does it mean that "Object Oriented Programming imposes discipline on indirect transfer of
What does it mean that "Object Oriented Programming imposes discipline on indirect transfer of

Time:07-02

I have recently finished reading Clean Architecture book by Unckle Bob. There he wrote

Three paradigms. Three constraints. Structured Programming imposes discipline on direct transfer of control. Object Oriented Programming imposes discipline on indirect transfer of control. Functional programming imposes discipline upon assignment. Each of these paradigms took something away. None of them added any new capability. Each increased discipline and decreased capability.

  1. What does indirect transfer of control mean?
  2. How it is restricted in OOP?

CodePudding user response:

  1. What does indirect transfer of control mean?

Pointers to functions.

  1. How it is restricted in OOP?

Polymorphism.

A more complete explanation can be found on the bottom of page 42.

The bottom line is that polymorphism is an application of pointers to functions. Programmers have been using pointers to functions to achieve polymorphic behavior since... the late 1940s.

The problem with explicitly using pointers to functions to create polymorphic behavior is that pointers to functions are dangerous. Such use is driven by a set of manual conventions. You have to remember to follow the convention...

OO languages eliminate these conventions and, therefore, these dangers. Using an OO language makes polymorphism trivial. That fact provides an enormous power... On this basis, we can conclude that OO imposes discipline on indirect transfer of control.

The discipline imposed in OO is that pointers to functions are accessed exclusively through polymorphism and never used explicitly.

  • Related