Skip to content
Yehonathan Sharvit edited this page Apr 5, 2021 · 1 revision

Loose coupling

Definition

A system is loosely coupled when its components have little knowledge of the internals of other components.

Components A is loosely coupled with component B if A communicates with B without concrete knowledge about the internals of B.

Example

Web services that communicate via JSON are loosely coupled.

In Clojure

In Clojure, inside a program we "just use maps" to communicate. This is based on the principle that "we should program the insides of our systems like we program the outsides". Outside, we have loose coupling everywhere: over the wire we communicate via data (e.g. JSON). Let's do the same inside and communicate via data (e.g. hash maps).

Compare that with functions that receive a record (or a data class) as an argument. In order to call those functions, we need to import the definition of the record. That's not loose coupling!

See also

Abstraction, Concretion

Clone this wiki locally