什么使Java Collections成为一个框架?(我没有看到任何“控制反转”)

huangapple go评论141阅读模式
英文:

what makes java Collections a framework? (I don't see any 'inversion of control')

问题

Google搜索给出的是:“Java中的集合是一个框架...”。进一步的搜索给出的是:“库和框架之间的关键区别是‘控制反转’”。我认为在集合的上下文中,框架并不是指控制反转。请解惑一下。

英文:

Google search gives me, 'The Collection in Java is a framework...'. Further search gives me, 'The key difference between a library and a framework is "Inversion of Control"'. I reckon in Collection's context, framework is not used in the sense of IoC. Please enlighten.

答案1

得分: 1

主要区别在于Library和Framework之间:

Library = 一组有用的组件

Framework = 一组有用的组件 + 使用这些组件的工具


Library 是一组可重用的组件。
它为用户提供了在调用或使用组件方面的灵活性。

Library的现实世界类比
传统的城市出租车服务就像一个图书馆。
可以通过挥手,喊“出租车...”或拨打电话来叫出租车。


Framework 是一个带有一些用于使用该库的工具的库。

Framework提供了额外的好处,通过提供一种高效的内置方法来使用这些组件。

Framework的现实世界类比
带有自己应用程序的出租车服务就像一个框架。
不能通过挥手或喊“出租车...”来叫出租车。
出租车只能通过使用该应用程序来预订。


Java Collections 被标记为一个框架,而不是一个库,因为它附带了一些有用的算法实现(排序、队列管理等),以及一组有用的组件(List、Set、HashMap等)。

例如,Java Collections Framework为对象排序提供了高效的内置算法。

程序员可以选择使用内置的排序工具或编写新的算法。

由于内置算法是与组件一起提供的,因此Java Collections被视为一个框架,而不仅仅是一个库。

英文:

The main difference between Library and Framework is:

Library = Set of useful components

Framework = Set of useful components + Utilities to use the components


Library is a set of reusable components.
It provides flexibility to the user on the way in which the components can be called or used.

A real-world analogy of Library:

Traditional City Taxi service is like a library.

Taxi can be called by waving hand, or by shouting 'Taxi...', or by calling a telephone number.


Framework is a Library that comes packaged along with some utilities for using the library.

Framework provides an extra benefit, by offering an efficient built-in way of using the components.

A real-world analogy for framework:
A Taxi service that comes with its own app is like a framework.
The Taxi cannot be called by waving hand or shouting 'Taxi...'.
Taxi can be booked only by using the app.


Java Collections is labeled as a framework, instead of as a library, because it comes with some useful implementations of algorithms (sorting, queue management, etc) along with the set of useful components (List, Set, HashMap, etc).

For example, Java Collections Framework provides an efficient built-in algorithm for sorting objects.

The programmer can choose to either use the built-in sorting utility or write a new algorithm.

As the built-in algorithms are provided along with components, Java Collections is considered a framework, rather than just a library.

答案2

得分: 0

一个“框架”并不意味着控制反转。

这个术语没有明确定义,可以从在线上找到不同的定义。

例如,techterms.com 解释说:

一个框架,或者软件框架,是开发软件应用的平台。它为软件开发人员提供了构建特定平台程序的基础。 例如,一个框架可能包括预定义的类和函数,可以用来处理输入,管理硬件设备,并与系统软件交互。这简化了开发过程,因为程序员在开发新应用程序时不需要重新发明轮子。

“Java集合框架”是一个很好的“构建程序的基础”。这就是它的全部含义。

英文:

A "framework" doesn't imply IoC.

The term is not well-defined, proven by the fact that you can find different definitions online.

E.g. techterms.com says:

> A framework, or software framework, is a platform for developing software applications. It provides a foundation on which software developers can build programs for a specific platform. For example, a framework may include predefined classes and functions that can be used to process input, manage hardware devices, and interact with system software. This streamlines the development process since programmers don't need to reinvent the wheel each time they develop a new application.

The "Java Collections Framework" is a good "foundation for building programs". That's all it means.

huangapple
  • 本文由 发表于 2020年9月17日 03:00:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63926426.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定