Differences Between Frameworks and Libraries
- Published
Some thoughts on the difference between a framework and a library.
Dependency inversion?
The most common distinction seems to be whether there is dependency inversion: if my code calls it, it is a library; if it calls my code, it is a framework.
When the boundary is unclear
But the boundary is often less than clear.
A library can have callbacks, and I can call a framework too, as with the template method pattern.
When it depends on the user
Some libraries/frameworks can be used more like a framework or more like a library, depending on how you use them. So I tend to disagree with claims such as “React is a library because the React developers say it is a library”—something I hear fairly often.
Distinguishing them by how much they constrain you
The distinction I prefer is this.
I find it useful to think in loose terms: the more constraints something places on my code, the closer it is to a framework; the fewer constraints it places on my code, the closer it is to a library. This holds whether those constraints arise from the design of the code itself or from the way I use it.
Thinking in degrees rather than exclusive categories is often useful. Even when the boundary between two concepts is fuzzy, having terms for them can sometimes help, so I do not think the distinction itself is meaningless.