Object-Oriented Programming

IoC: Inversion of Control

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

 

Sequence Diagram: Original

  • Scenario: Single key/value
  •        Docker Report code
  •        Low-level YAML parsing code
  •        YAML parsing loop code
  • Full Diagram

UML Class Diagram: YAMLParser

 

Sequence Diagram: YAMLParser

  • Scenario: Single key/value
  •        Docker Report
  •        Low-level YAML parsing
  •        YAML parsing loop
  • Full Diagram
  • Compare to Original

Control Flow

Callback

Inversion of Control

  • IoC
  • Inverts part of the control flow of the program
  • Instead of your code calling a function/method, you register parts of your code, and the function/method calls those parts of your code at the appropriate time
  • Similar to much event-driven programming
  • For low-level functionality with a function, typically called a callback
  • May be a single method or entire object
  • Essential for frameworks

UML Class Diagram: YAMLParser IoC

 

Sequence Diagram: IoC YAMLParser

  • Scenario: Single key/value
  •        Docker Report
  •        Low-level YAML parsing
  •        YAML parsing loop
  • Full Diagram
  • Compare to non-IoC