Even after spending years of your life in computer science, if you don’t know the difference between Library and Framework, believe me, you are not alone.
There are many programmers and developers out there who have already used dozens of frameworks and hundreds of libraries in their career, but when someone asks this question, they are like “Framework is a collection of many libraries” and that’s it.
This definition is not completely true. The actual difference lies in the way one calls another. In simple words, the code we write calls the library code, but in a framework, it is the framework’s code which calls our code. So, let’s take a look at both of these industry jargons in detail.
What is a Library?
A library usually focuses on a narrow scope. It provides a set of helper functions, methods, etc which you can call in your project to achieve specific functionality. It’s basically a collection of class definitions which is written mainly to promote code reuse. There’s no need to start from scratch every time, you can easily use written by others to save time and energy.
As Library has a narrow scope, the APIs are also smaller and ultimately the project require fewer dependencies to get the things done. Suppose, Util library of Java has a reverse() method to reverse any string. Now, you don’t have to declare variables and run loop to reverse a string, you can call sb.reverse() and that’s it.
Here, String str = “RandomText” and StringBuilder sb = new StringBuilder(str). Other examples include image manipulation, string utilities, regular expression, etc.
What is a Framework?
Frameworks are like the foundation on which developers build programs for specific platforms. These are designed to decrease the number of issues that a computer programmer faces during the development.
Frameworks may have defined or undefined functions and objects which the programmer can use or overwrite to create an application. The major task of a framework is to provide a standardized code that can be applied to a variety of application projects.
If you know or have worked with C++ or Java, you can relate this concept to implementing abstract functions/methods. Frameworks have a wider scope and include almost everything required to make a custom user application. Some of the popular frameworks are Node.js, AngularJS, etc.
Library vs Framework: The Key Difference
Both the Library and Framework plays a vital role in software development. A library performs a specific or well-defined operation, whereas a framework provides a skeleton where programmers define the application content of the operation.
But when it comes to the Key difference, I would say – Inversion of Control. When we call a function or a method from a library, we are in control. But in the other case, the framework calls our code and thus the control is inverted. In most of the cases, the framework only provides the concept. It’s the application’s job to further define the functionality for end users.
I hope this article helped you understand the difference between a library and a framework. There are thousands of libraries available for almost every language, and helping programmers to reuse the code written by others. On the other hand, frameworks help them focus on development rather than issues.