What is the difference between a Library and a framework? The two concepts are important but sometimes confusing for developers.

1. Key Difference and Definition 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.

framework-vs-library

A library is just a collection of class definitions. The reason behind is simply code reuse, i.e. get 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 which can let developer just call the function without redo the implementation of how an algorithm works.

In framework, all the control flow is already there, and there’s a bunch of predefined white spots that you should fill out with your code. 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 when 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.

Example


To better understand the difference between a library and a framework, let’s take a look at jQuery and AngularJS. jQuery is a cross-platform JavaScript library that simplifies the manipulation of the DOM along with a lot of other complex things like CSS manipulation, HTML event methods, AJAX calls, etc. The goal of jQuery is to make it easier to use JavaScript on your website.

AngularJS, on the other hand, is a structural framework based on the MVC architecture used to build dynamic web applications. It is completely based on HTML and JavaScript, and unlike jQuery, it cannot be integrated into existing projects because, as a framework, it determines how your code should be structured and executed.

Reference:

https://martinfowler.com/articles/injection.html

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *