Composition refers to the way in which something is put together. Composition is a key element in many of the things humans create. Wether it be a musical piece, a painting, a garden, or a building, the way we assemble the core components - the composition of them - has a significant impact on the overall experience.
Software composition is about constructing complex systems by piecing together smaller, distinct components into modules and piecing modules together into systems.
A complex system that works is invariably found to have evolved from a simple system that worked. A complex system designed from scratch never works and cannot be patched up to make it work. You have to start over with a working simple system.
- John Gall (Gall’s Law) 1
Each of these smaller, distinct components should exhibit a set of characteristics. They should be small, have a single evident purpose that they consistently do well, operate as independently as possible, adhere to agreed idioms (standards and conventions), promote intentional observability (the ability to monitor what the software is doing), and represent the problem domain for which they are intended.
For an excellent, more in-depth read on these characteristics, I recommend Dan North’s article on CUPID2. Dan has had a tremendous influence on the way I think about software over the years.
When our components - functions, methods, procedures, routines - exhibit the desired characteristics, they are better able to be assembled into larger modules - classes, libraries, functional compositions - with low risk and high reliability.
Modules should exhibit the same characteristics as components. They should additionally collect together closely related concepts (known as cohesion) and be structured in such a way that they have as few dependencies as possible on other modules (known as coupling). We want high cohesion and low coupling.
This approach to development allows us to ultimately create systems from well composed modules and components, creating systems that are relatively independent, observable, reliable, and malleable.
We will cover more on composition, including tools, techniques, and principles in future articles.
https://en.wikipedia.org/wiki/John_Gall_(author)#Gall's_law
https://dannorth.net/cupid-for-joyful-coding/