Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>All three of those provide functionality.</p> <p>However, there are important differences.</p> <p>A <strong>library</strong> is <em>just</em> a collection of related functionality. Nothing more, but also nothing less. The defining characteristic of a library is that <em>you</em> are in control, <em>you</em> call the library.</p> <p>The defining characteristic of a <strong>framework</strong> is <em>Inversion of Control</em>. The framework calls <em>you</em>, not the other way round. (This is known as the <em>Hollywood Principle</em>: "Don't call us, we'll call you.") The framework is in control. The flow of control and the flow of data is managed by the framework.</p> <p>You can think of it this way: in both cases, you have an application, and this application has holes in it, where code has been left out, and these holes need to be filled in. The difference between a library and a framework is</p> <ul> <li>who writes the application,</li> <li>what are the holes and</li> <li>who fills in the holes.</li> </ul> <p>With a library, <em>you</em> write the application, and you leave out the <em>boring</em> details, which gets filled in by a <em>library</em>.</p> <p>With a framework, the <em>framework writer</em> writes the application, and leaves out the <em>interesting</em> details, which <em>you</em> fill in.</p> <p>This can be a little confusing at times, because the framework itself might also contain boring details, that the framework author filled in with libraries, the parts that you write might contain boring details, that you fill in with libraries, and the framework might provide a set of bundled libraries that either work well with the framework or that are often needed in conjunction with the framework. For example, you might use an XML generator library when writing a web application using a web framework, and that XML library might have been provided by the framework or even be an integral part of it.</p> <p>That doesn't mean, however, that there is no distinction between a library and a framework. The distinction is very clear: Inversion of Control is what it's all about.</p> <p>The defining characteristic of a <strong>module</strong> is <em>information hiding</em>. A module has an <em>interface</em>, which explicitly, but abstractly specifies both the functionality it provides as well as the functionality it depends on. (Often called the <em>exported</em> and <em>imported</em> functionality.) This interface has an <em>implementation</em> (or multiple implementations, actually), which, from the user of a module are a black box.</p> <p>Also, a library is a <em>collection</em> of related functionality, whereas a module only provides a <em>single piece</em> of functionality. Which means that, if you have a system with both modules and libraries, a library will typically contain multiple modules. For example, you might have a collections library which contains a <code>List</code> module, a <code>Set</code> module and a <code>Map</code> module.</p> <p>While you can certainly write modules without a module system, ideally you want your modules to be separately compilable (for languages and execution environments where that notion even makes sense), separately deployable, and you want module composition to be safe (i.e. composing modules should either work or trigger an error before runtime, but never lead to an runtime error or unexpected behavior). For this, you need a module system, like Racket's units, Standard ML's modules and functors or Newspeak's top-level classes.</p> <p>So, let's recap:</p> <ul> <li><strong>library</strong>: collection of related functionality</li> <li><strong>framework</strong>: Inversion of Control</li> <li><strong>module</strong>: abstract interface with explicit exports and imports, implementation and interface are separate, there may be multiple implementations and the implementation is hidden</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload