Difference between a module, library and a framewo

2019-01-29 15:33发布

In popular programming speak, what is the difference between these terms and what are the overlaps?

Any related terms I'm missing out?

9条回答
Lonely孤独者°
2楼-- · 2019-01-29 15:52

From my point of view a framework contains libraries and both are modules.

E.g. In Swift a module is a single unit of code distribution — a framework or application that is built and shipped as a single unit.

查看更多
再贱就再见
3楼-- · 2019-01-29 15:53

I believe frameworks and libraries are modules. Since modules are codes imported or exported from your code. As they say, Frameworks calls your code, your code calls libraries. Either way, a module is involved

查看更多
对你真心纯属浪费
4楼-- · 2019-01-29 15:53

Module

A module is the output of modular design, a component with various granularity.

In context of modular programming, a module is an entity expressible by the coding language introducing the programmability (typically, a programming language or a hardware description language) to the solution.

Some languages explicitly support the concept of module and provide it as a language feature. A notable early instance is Modular-2. Despite the feature, users can still specify other kinds of modules by conventions with different granularity in software design and project management, like a source file and a directory of source files. The built-in language feature does not eliminate the need of modules of different granularity, but people may use different terminology to avoid possible ambiguity with the language feature.

Some other languages do not provide specific feature named module, but users can make choices to specify parts of program as modules. For example, the C language does not have modules, but users can specify a function, a source file, a translation unit (a source file with the headers it includes) or even bunch of files as a module on demand. A module in such case can be with different forms of code: source, binary code from source or provided elsewhere with linkage compatibility guarantees, or even mixed.

The only real restriction of "module", if any, is that it should reflect to the result of some modular design, so components in a module should share some similarities to make the boundary clear. A module should usually provide some kinds of exported interface to users; it may optionally import dependencies from external program components. Some of modules can be a submodule of others.

Code management tools may utilizes the concepts related to module. For example, Git has the concept of submodule, which is essentially a versioned subdirectory of code in the repository.

Library

A library is a specialized kind of program module containing (more specifically, owning) a collection of (sub)modules to be used in some encapsulated (that is, not allowed being modified directly in later use) manner. Usually a library is designed to be reused and deployed within non-volatile storage. Typically, a library is provided as one or several on-disk files in some steady persistent formats. Such libraries are called archives, dynamic objects, packages, etc. With support of external program databases, libraries can also be identified by means other than filenames or other file-based properties. For example, CLI provides library assemblies with aid of GAC.

Framework

A framework is another specialized kind of program module which contains various pre-desinged functionality of code. A framework can be deployed in a form of one or several libraries. The difference between a framework and other kinds of modules in a program is that the former emphasizes a mostly complete, freezed but adaptive and extensible solution of some common work, so the user of the framework can focus on the domain-specific and project-specific problems instead of writing glue code to put different libraries together and to make them work fluently. However, this has a cost of design complexity throughout the whole project. Notably, many (but not all) frameworks would enforce users' code following an IoC style. As a result, it is almost impossible to put same kind but different frameworks together smoothly in an idiomatic and natural way. Using language with first-class control effects, IoC is not explicitly required in a framework. However this implies that combination of normal libraries to having functionality of a framework is easier to achieve, so there is less need to organize program modules like traditional frameworks which often undermine flexibility easily.

查看更多
The star\"
5楼-- · 2019-01-29 16:01

In my opinion a module could be a subset of a library, which in turn could be a subset of a framework. But I'm sure there are exceptions to this and various interpretations based on the context -- especially for the term module.

查看更多
神经病院院长
6楼-- · 2019-01-29 16:05

My ASCII art interpretation of what I understood from other answers:

+-----------------------------------------------+
|  ...........................  ..............  |
|  : f1() f2()  :  f3()      :  : f4() f5()  :  |
|  :            :            :  :            :  |
|  : l1_module1 : l1_module2 :  : l2_module3 :  |
|  :            :            :  :            :  |
|  --library1-----------------  --library2----  |
|                                               |
|   application.c                               |
|                                               |
|       #include l1_module2                     |
|       #include l2_module3                     |
|                                               |
|       int main() {                            |
|           # case 'reload'                     |
|           f5();                               |
|           # case 'start'                      |
|           f1();                               |
|           # case 'stop'                       |
|           f4();                               |
|       }                                       |
|                                               |
+-----------------------------------------------+

.................................................
: FRAMEWORK_X                                   :
:                                               :
:     application start                         :
:     ...                                       :
:     application reload                        :
:     application stop                          :
:     ...                                       :
:...............................................:

What happens:

  1. Developer installs library1 and library2 so that they can use functions provided inside modules of these.

  2. They then include l1_module1 and l2_module3. (They do not need l1_module2 for now).

  3. Now they can use the functionality of f1, f2, f4 and f5, So they write their application.

  4. Now, since they want to use the application inside some FRAMEWORK_X, they must implement the interface that this framework needs: so that the framework can call the application.

Some notes:

  • In practice, there is always some framework. For example, the OS is framework for your application (which is why you define main())! Or you could say that the bootloader is framework for your OS and the BIOS is framework for your bootloader etc.
查看更多
闹够了就滚
7楼-- · 2019-01-29 16:06

You can see a module, a library and a framework this way:

  • module = your fingers
  • library = your hands
  • framework = your body

Your fingers / Module:
You can move them, touch things, you have 5 in a hand so you can use them to hold things in an easier way, those are not the biggest parts of the body but are one of the most useful parts, without them you couldnt hack!... modules are part of a program, you can use them, expand code to other files (not a large file with a lot of code in it), they make the reading easier.

Your hands / Library:
Hands are a set of 5 fingers each one, you can hold things, move things, interact with them, etc... libraries are part of a program too! and they can be seen like a set of modules, you can use them to interact with other programs or make relevant things with your program.

Your body / Framework:
Your body is a complete system, you can do with your body whatever you want (even fly, just walk into a plane and there you go, a plane is another system), you are unique... a framework is your body, a complete system, it doesnt work for itself (you need to code herpderp) but you can make a complete program with some hacking runs...

just my interpretation... if im wrong please fix ME.

查看更多
登录 后发表回答