In the illustration above, the framework controls the execution flow and calls the developer’s code, following the Inversion of Control principle. In contrast, libraries provide reusable functions that the developer’s code calls directly when needed. Libraries offer specific functionality without dictating an application’s overall structure or flow, whereas frameworks set the structure and dictate when certain code is executed.
Now, let’s understand their relationship with the help of a scenario. Consider a team building a web application. The framework is like the skeleton and architecture of the web application, defining how everything fits together. Libraries are pre-built tools and equipment for specific tasks, such as a library for user authentication or database connections. The role of code is custom work to make the application unique, like designing the interior and adding special features.
When code runs, it often needs to use these prebuilt tools from libraries to save time and effort, just as builders use specialized tools on a construction site. Conversely, the framework may call the code at certain points, such as when a web request comes in, to let you customize how it responds. This back-and-forth interaction ensures the application is structurally sound, meets specific requirements, and functions effectively.
Frameworks
Now that we’ve explored the basics of frameworks, let’s look at some popular examples of each in action. The example of frameworks are: