Why is the STL considered a library, but the JCF a framework? What exactly is it in their respective designs that causes/justifies this distinction? Can you give a code example that illustrates this?
Asked
Active
Viewed 1,340 times
3
-
2I think, with a library your code is using the library, whereas with a framework the framework uses your code. Roughly. With a framework your code has to *fit in* with the framework, it has to be adapted to the framework and mostly restricted to what the framework supports. – Cheers and hth. - Alf Mar 21 '12 at 20:01
-
If I pass a Comparator to `std::sort`, isn't the STL also using my code? – fredoverflow Mar 21 '12 at 20:03
-
I'm not sure where the dividing line is exactly. But it's a matter of degree of control inversion. With `std::sort` you're merely customizing a particular call of a library function, while with a framework you'd override some comparator function in a "Sorter" functor class and create an instance of that class, sort of? – Cheers and hth. - Alf Mar 21 '12 at 20:12
-
Java uses a simple `Comparator` interface with a `compare` method. You pass an object of a class that implements that interface to `Collections.sort`... I really don't see any conceptual difference. – fredoverflow Mar 21 '12 at 20:14
-
I believe "framework" is used as a buzzword here, were `framework` sounds *better designed* than a library, for example from the [Oracle Site](http://docs.oracle.com/javase/tutorial/collections/intro/index.html) - `..the best-known examples of collections frameworks are the C++ Standard Template Library (STL) and Smalltalk's collection hierarchy` so even Oracle considers the STL to be a "Collections Framework". – Jesse Good Mar 21 '12 at 21:30
1 Answers
4
Definition by Martin Fowler:
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.
More discussion can you find here: What is the difference between a framework and a library?
-
Do you have an example where the JCF call my code, but the "equivalent" STL example doesn't? – fredoverflow Mar 22 '12 at 09:36