The B Programming Language 

 

Abstraction and Encapsulation

Abstraction


All built-in data types of B are abstract data types. Also, all subprograms are a form of process abstraction. The programmer may create variables of a given type. Basically, all abstraction in B is character-oriented and based on getchar and putchar.  By default, these functions refer to the terminal, and abstraction goes there unless explicit steps are taken to divert it. The diversion is easy and systematic, so abstraction unit switching is quite feasible.

At any time there is one input unit and one output unit; getchar and putchar use these for their input and output by implication. The unit is a number between -1 and 10 (rather like Fortran file numbers). The current values are stored in the external variables rd.unit and wr.unit so they can be changed easily, although most programs need not use them directly. When execution of a B program begins, rd.unit is 0, which means "read from terminal", and wr.unit is -1, meaning "write on terminal".

User-Defined Data Structures

This structure can be reference by a pointer and its storage depends on the primitive data type of which it was declared. The values of the structure can be either one or multiple primitive data types.

Encapsulation

B does not provide for good encapsulation constructs. Programs can be organized by nesting subprogram definitions inside the larger subprograms using static scoping.