The Difference Between a Framework and a Library
You might be thinking it’s a very basic topic for any programmer. Yes, It is really basic stuff. But sometimes we never bother about the clarity about the basics and we try to relate always with different things. Likewise, Developers often use the terms “library” and “framework” interchangeably. But believe me, there are many differences. Let’s find out the difference and come out with a better and conclusive definition for both the terms throughout this article.
We all have been to school for almost 10-15 years of our life, some of us may even spend our time more then that in school in case we are over intelligent ( if we failed in 2-3 times in a class, like me ) . So, let’s take a common and simple example of the school and our home.
What do you think what may be the differences between both? There are a lot of differences with the look, location and many more. But, one most important difference is rules and regulations. “In the case of a home, we are the principal, we can do whatever we want, we can make a call for anything. We can throw our stuff anywhere, we can seat anywhere, etc. There are no rules and regulations and we are free to do the things we want. On the other side, In the case of school, our principal/professor/teacher used to be some fat person with thick mustaches or any beautiful old lady with a number of rules, isn’t it? There are rules and regulations we had to follow and Bla…Blah…Blah..”.
Likewise, “Library is like our home and control is in our hand, where we can make our call as per the need of code or requirement. But, Framework is like school where all the controls are under the framework and we need to follow rules of the framework”.
Although, both frameworks and libraries are code written by someone else that is used to help solve common problems. Their purpose is to help you solve common problems in easier ways. Now we can conclude Major differences as follows
- Caller Relationship: This is the one, who defines the differences between both terms i.e “Who calls whom”. In case of Library, it is our code which makes the call to Library as per the need. But, in case of Framework, it is the framework’s code which calls our code.
- Inversion Of Control: It is an extension of the caller relationship. When we call a method from a library, we are in control. But in framework, the control is inverted i.e. the framework calls us.
- Technical Difference: When you use a library, you are in charge of the flow of the application. You are choosing when and where to call the library. When you use a framework, the framework is in charge of the flow. You always need to work under the frame of the Framework.
- Scope: Library typically focus on narrow scope, i.e a library provides a set of helper functions/objects/modules which your application code calls for specific functionality. On the other side, a framework is itself an application, it has a wider scope and includes almost everything necessary to make a user application as per his own needs.
Definitions for Library and Framework
Library: It is a set of helper functions/objects/modules which your application code calls for specific functionality and performs a set of specific and well-defined operations. It is a collection of precompiled modules that a program can use. Libraries are particularly useful for storing frequently used modules because you do not need to explicitly link them to every program that uses them.E.g
Framework: It is known to be a structure/frame where the application defines the content of the operation by filling out the frame. It provides a fundamental structure to support the development of applications for a specific environment. Examples of frameworks: Web application system, Plug-in manager, etc. The framework may or may not be the collection of the library. It has defined open or unimplemented functions or objects which the user writes to create a custom application.