DEV Community

Beth
Beth

Posted on • Edited on

Framework vs Library

Framework vs Library


The terms "framework" and "library" tend to be used interchangeably in software engineering. Frameworks and Libraries are both reusable code written by someone else to help us solve common problem in easier ways. However, despite this similarity, there are some differences between the two. Some of these differences are shown below.

Inversion of Control

One key difference between a Framework and a Library is called inversion of control.

In the case of a framework, the framework is in charge of the flow of the application. It provides some places to plug in our code, but it calls the plugged in code as needed. Frameworks contains the basic flow and we only need to write the behavior. In other words, the framework code calls our code.

On the other hand, libraries allow us to control the flow of the application. We choose when and where to call the library. This means, we will need to understand the functionally of each method being used and decide when our code calls the library code.

So we can say using a Framework is like buying a new home. The house is already built, so you don’t have to worry about building problems. You can't choose how the rooms are arranged; however, you can choose what furniture goes in each room.

On the other hand, using a Library is like building your home from the ground up. The house can be made in any style you prefer and the rooms can be arranged and decorated however you like.

Replaceability

Another difference between a Framework and a Library is that frameworks are not as easily replaceable as libraries are.

Once we write our code in a framework (for example, in AngularJS), and if we decide to replace this framework, we will need to re-write all the code in the application.

On the other hand, if we are using a library (for example, React), and don't like it, we can replace it with another library (for example, with jQuery). This will require some rewriting of code; however, we won't have to start from nothing.

Adding Functionality to Existing Projects

If we have an existing project and we wanted to add a new functionality to it, then incorporating frameworks seamlessly into the existing project is impossible. Frameworks should be used when starting a new project.

Libraries are instead easier to add to an existing project. We can integrate libraries seamlessly into existing projects to add functionality. We can even add multiple libraries in on application if we needed without having to replace the existing one.

Learning Curve

Compared to Libraries, Frameworks have steeper learning curves. Because Frameworks provide the flow of the code, it takes more time initially to understand and learn them.

On the other hand, Libraries have shorter learning curve than Frameworks do.

Conclusion

As shown above there are some advantages and disadvantages for both Frameworks and Libraries. Depending on the situation of your project one might be a better option than the other.

Examples of Javascript Frameworks

  • Bootstrap
  • Angular and AngularJS
  • Ember.js
  • Aurelia
  • Vue.js

Examples of JavaScript Libraries

  • jQuery
  • Underscore and Lodash
  • D3.js
  • React
  • Redux

Resources

freeCodeCamp
baeldung
TheServerSide

Top comments (0)