The Modularity Principle

The modularity principle is the most basic principle in engineering. It states:

Systems should be built from cohesive, loosely coupled components (modules).

A cohesive component has a well defined function or purpose.

Components are loosely coupled if their interdependencies are minimized.

Cohesive, loosely coupled components are easy to understand, reuse, and replace.

Component Interfaces and Implementations

The interface of a component describes the component's function. Following the Abstraction Principle, the interface of a component should be independent of its implementation. By similar logic, components should depend on the interfaces of provider components, not their implementations:

Example

Modern computers are built around a printed circuit called a motherboard. Computer chips (integrated circuits or ICs) are mounted on the motherboard. An IC can be viewed as a component. An IC such as a CPU has a well defined purpose: to execute machine language programs.  An IC's input and output pins give it a well defined interface to the motherboard and thus to the other ICs.

Motherboards also provide expansion slots. Expansion cards can be plugged into these slots to add new functionality to the computer such as enhanced graphics and sound. We can view the expansion cards as components, too.

Example

The components of a program can be packages:

Example

The components of an object-oriented program can be classes:

Example

UML component diagrams model systems from the perspective of components (components), interfaces (lollipops and sockets), and dependencies: