Library vs Framework

Syed hadi azfar
3 min readJan 8, 2021

--

What is Library:

A Library is a Code which is written by Someone Else previously and can be called when you are building your own code, it means it is a collection of code packed together to use over and over again, which helps you to solve a specific problem or add a specific feature to your program. A library is just a collection of class definitions. The reason is it simply code reuse, in other words, gets the code that has already been written by other developers. The classes and methods normally define specific operations in a domain-specific area. For example, there are some libraries of mathematics that can let developers just call the function without redoing the implementation of how an algorithm works. A library will usually focus on a single piece of functionality that you access using an API. You call a library function; it executes some code and then the control is returned to your code.

What is a Framework:

A Framework is also the Code written by Someone Else with the purpose of helping you solve common problems in easier ways. It is a supporting Structure where your own code defines the operations by filling out the structure. A framework is normally more complex. It defines a skeleton where the application defines its own features to fill out the skeleton. In this way, your code will be called by the framework appropriately. The benefit is that developers do not need to worry about if a design is good or not, but just about implementing domain-specific functions. The framework will provide you with hooks and call-backs so that you build on it; it will then call your plugged-in code whenever it wishes, a phenomenon called Inversion of Control.

Key Difference of Library and Framework

The key difference between a library and a framework is “Inversion of Control”.

When you call a method from a library, you are in control. But with a framework, the control is inverted: the framework calls you.

Now to better understand them, first we need to look at each one separately.

Why use a framework instead of a library:

When you have a library, you need to understand the functionality of each method and it is relatively hard to create complex interactions since you need to invoke many methods to get to results. Frameworks, on the other hand, contain the basic flow and since you only need to plug in your behaviour it is easier to do the right thing. In the GIS example that prompted this discussion, it would be better to have a framework since there are hundreds of interfaces you can use. However, what most users want is an easy way to make a UI entity appear on a map.

--

--