Library vs framework: what is the key difference?
Options
- You call a library; a framework controls the flow and calls you (Correct option)
- They are exactly the same thing, with two different names
- A library is paid software and a framework is always free
- A framework is always smaller and simpler than a library
Answer
You call a library's code when you need it; a framework has the main flow and calls your code at points it defines (inversion of control)
Why
Martin Fowler describes a library as a set of functions that you call. A framework embodies an abstract design, and its code calls yours: 'Don't call us, we'll call you'.
Examples: requests and Jackson are libraries. Spring Boot and Django are frameworks.
MDN adds that a framework is a library that offers opinions about how software gets built.
Remember
Library: you call it. Framework: it calls you.