Direct and Indirect Input/Output

Direct Input

A program element is said to operate on direct input if it only relies on input passed through its public interface.

Examples

This canonical snippet works in C, C#, and Java.

int add(int augend, int addend) {
    return augend + addend;
}

Indirect Input

Indirect input is that which cannot be observed through the public interface.

Examples

  • Create a new collaborator and have it supply some input
  • Read data from a file
  • Read data from a socket, remote API, or use some other form of network connection
  • Read data from a database or message queue

Direct Output

A program element’s direct output is observable through its public interface.

Examples

This example in Groovy illustrates the basic case of just returning a value.

def add(int augend, int addend) {
    augend + addend
}

A little contrived, but this C snippet shows that using pointers as out parameters indeed results in direct output.

#include <stdio.h>

void add(int augend, int addend, int *sum) {
  *sum = augend + addend;
}

int main() {
  int sum;
  add(2, 5, &sum);
  printf("%d\n", sum);
  return 0;
}

Indirect Output

Indirect output is output that isn’t observable through the public interface.

Examples

  • Print something to stdout
  • Create a new collaborator and have it supply some input
  • Write data to a file
  • Write data to a socket, remote API, or use some other form of outgoing network connection
  • Write data from a database or message queue