What is the major difference between a framework a

2019-01-14 07:21发布

问题:

Does a framework allow you to abstract generic code - but not in a complete way (Ex: Abstract a network connection - but not what you actually do with the data), and does not solve any particular common requirement whereas a toolkit has solutions to generic problems(Ex: Dialog box widget)?

Real world Example: Prototype is a "framework", but Dojo is a "toolkit".

So my question is, what is the criteria to call something a framework vs calling it a toolkit?

回答1:

Framework enforces some design pattern on the developer and give some tools for code generation. This sits well with my first sentence, as it generates code in a certain style/pattern.
Library gives you functionality for you to use as you wish. Like the stdio functions of C, Console of C#, The "built in" functions of PHP etc
You can regard a library as a kind of API



回答2:

Quoting Martin Folwer in his article on Inversion of Control:

Inversion of Control is a key part of what makes a framework different to a library. A library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client.

A framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points.

So in short, the big difference is that your code calls a library while a framework calls your code.



回答3:

In my book, a framework provides a structure and encourages or requires that it be used in a certain way. This can be good if the developer wants to do things the framework's way, since it's easier for many thing to be automatic, but it can be bad if the developer wants to deviate from the framework's intent.

A toolkit, on the other hand, provides various tools that can be used together or separately. It's more flexible but requires more effort on the programmer's behalf.