在Java的接口上(计算机编程中接口的含义) [英] On Java's Interface (the meaning of interface in computer programing)

查看:88
本文介绍了在Java的接口上(计算机编程中接口的含义)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java的界面上


Xah Lee,20050223


在Java语言中,有一个关键字a ??界面??


在函数式语言中,函数可以通过其名称和

参数规范来指定。例如:

f(3)

f(3,[9,2])

f(" some string")


是3个函数的使用示例,它们都具有相同的名称,但具有不同数量和类型的参数。通过这种方式,函数可以通过名称和参数规范为外人所知。这个概念的要点是用户不需要知道该函数的

实现细节。她需要知道的是

函数的名称,参数规格和返回值规范。 (以及

当然该函数应该做什么。)这样,界面

和实现是分开的。实现可以随时改变或者b $ b改善,用户不需要知道。


在Java中,上面的函数名称和参数规范的概念是
称为方法'的签名。


另一个例子,通常一个程序需要与另一个程序交谈

软件比如数据库软件。数据库软件可能有一套功能,用于与其他软件通信。

实质上,使数据库对其他软件有用。这样的列表

的函数规范通常称为API,它代表应用程序

编程接口。


API术语是被热爱营销的Sun Microsystems滥用

,将Java语言的文档称为Java APIa,甚至是

虽然Java语言及其语言图书馆的工具和

硬件仿真系统(所有这些一起被称为Java?

Platforma ??)不是应用程序,也不是接口。 (API暗示

涉及两个不同的实体,允许通过它进行通信。在Java APIa的情况下,它'是一个实体

与自己说话。)。


一般来说,编程中的界面概念是一种

规范允许不同的实体调用并使用另一个实体
,暗示调用者不需要知道幕后的'b
。 />

在面向对象编程范例中,出现了一个新概念,即
是a ??界面?一个类的方面。


正如我们所见,一个函数有参数规范,它就是用户需要知道的b / b
它。在Java中,这是方法''

a ?? signaturea ??。现在,随着OOP经验的方法论的增加,

显然界面概念也可以应用于

类。具体来说:一个类的接口是类的'

方法。


这个概念然后变成了一个OOP机器,希望

在软件工程中提取有用性。也就是说,现在在Java语言中,一个程序员实际上可以编写一段代码,

,其唯一目的是定义一个类的方法和变量

包含。这是用关键字a ?? interfacea ??完成的。一旦定义了一个接口

,其他类就可以说明它们实现了哪些接口,所以

如果C类实现了接口I,那么程序员就不需要

知道有关C的详细信息。他们需要知道的是接口I.

(指定所有方法,构造函数,变量,类)

必须有。)


(Java的界面,基本上是一个类的签名,在

Java''自己的行话。)


程序员可能会问,无论如何最重要的是什么?因为在Java中,无论如何都要记录
类。它与

有什么区别,知道C的文档与

C的界面文档?


Java中的接口是复杂性的增长。 Java

接口可以继承,就像类一样。这个想法是

接口也可以像类一样形成层次结构。


在纯粹的OOP中,例如Java,用于解决计算的对象实体

问题被认为是树的关系,因此我们有

类层次结构。以类似的方式,它被认为是界面,可以
也形成了一个富有成效的层次结构。一个很好的例子是列表数据

类型。解释如下:


在计算语言中,通常有一个不同的数据概念

作为列表,聚合,序列,数组,向量,元组, set,matrix,

trees ...基本的想法是它只是一个列表。此列表

可能不允许重复,元素可能是列表本身,可能有某些维度规定(例如矩阵),可能有某些

计算属性,例如检索元素的速度或者添加元素或内存占用等等的b $ b等等。不同的

要求和不同的计算属性给了他们各种名字
。然而,人们可以通过界面组织它们

透视。在Java中,它们被称为Collection,并且都具有Collection的

接口。 (参见 http:// java.sun.com/j2se/1.5.0/docs/...ollection.html
http://java.sun.com/docs/books/tutor...ces/index.html




考虑一个集合和列表。一个不允许重复,而

其他允许。除此之外,两个概念都是相同的。它们都需要添加元素,删除,插入,排序等方法。

因此,从界面的角度来看,它们共享一个父级。在Java中,

Set和List都是接口,继承自父接口

Collection。


现在,在Java中,我们有两个独立类别的层次结构:类

和接口。 Classes层次结构是一棵巨树。

但是,接口并不是一棵树。它们更像森林,许多树木。重要的是要记住

接口和类是独立的实体。一个类可以实现一个

接口。接口永远不能从类继承。


在Java中,一个类可以实现多个

接口。当类C实现接口I1和I2时,C是

保证接口I1和I2声明所有方法。对于

示例,在Java中,类Integer具有可比较的接口和

Serializable。类ArrayList具有以下接口:Cloneable,

Collection,List,RandomAccess,Serializable。


Java中的接口,来自一个简单有用的想法,变成了一个难以理解的复杂性。


在Java中,接口不再是程序员需要知道的唯一的东西。一个阶级或功能。它不再是一个概念,

将函数的用户规范与实现细节分开。


例如,ArrayList类具有以下接口:Cloneable ,

集合:List,RandomAccess,Serializable。正如可以从

名称推断的那样,它们更多地是关于ArrayList具有的属性,而不是隐藏实现无关的

语法外观。


例如,请参阅这些接口上的Java文档:a?¢

接口RandomAccess http://java.sun.com/j2se/1.5.0/docs/...domAccess.html


a?¢interface Serializable http://java.sun.com/j2se/1.5.0/docs/...ializable.html


a ?¢界面可比较的 http: //java.sun.com/j2se/1.5.0/docs/...omparable.html


我们可以看到这些界面是什么?真的不是界面

性质,而是属性。有人可能会问,在??界面中? suchas

RandomAccess没有单一的变量或方法,在什么

技术定义中,一个类据说可以满足这样的接口?

并且,鉴于存在这些类似属性的接口,是否可以定义他们自己的任意计算属性合约?

例如,假设我想要一个属性ConstantTime对于我正在开发的
游戏中的课程。有一次我宣布一个班级有一个??界面??

ConstantTime,显然我的班级不会神奇地变成

恒定时间。我如何为编译器定义任意属性,

以及编译器将如何检查?以下是答案。

20050224

Java的界面已经从界面概念变异了很多

it也可以作为纯标签。如果接口没有任何

变量或方法,则任何类都可以将其声明为接口。

无任何限制。例如,
Java中的RandomAccess接口没有任何变量或方法。任何类都可以声明它作为接口,可随机访问或不接受。当接口用作

标签时,它被称为a ??标记接口??通过Java文档。

例如,请参阅 http://java.sun.com/j2se/1.5.0/docs/...domAccess.html


由于Java接口的多继承性质,以及它作为标签的双重
角色,它不再作为通信外观起作用,即接口的含义。如果Java类具有接口A,B,C,

D,E,则无法确定

类具有哪些方法或变量。 (它将是他们的联盟,其中一些不提供

语言的任何功能。)此外,使用接口

作为惰性标签指示计算属性(例如,
RandomAccess)在计算语言设计中是一种令人震惊的无能。

用于计算。问题的关键在于它是语言中数学上不相关的一部分。作为

语言的标签机制,为了从软件工程中获得可能的好处

透视,那么它不应该被设计为类的一部分

接口,因为标签和编程接口在语义上是完全不同的。

关于标准Java教程的傻瓜


标准的Java教程通常都是愚蠢的,因为它们实际上并没有试图教授语言实际上明显做了什么,而是通常会说一些据称是好的工程

透视。


对于使用自行车进行界面的难以理解的形而上学介绍,

请参阅官方Java教程的这一页:
http:// java。 sun.com/docs/books/tutor...interface.html

有关使用令人困惑的财务的界面的详细说明
股票,请参阅官方Java教程的这一页:
http://java.sun.com/docs/books/tutor...interface.html

(官方Java)教程已于2006年进行了重大更改。对于

以上两页的版本,请参阅2005年的本地副本


PS官方Java教程通过它的更新历史改变了它关于什么是接口的

立场:

2005年之前的


定义:接口是一个命名的方法定义集合

(没有实现)。一个接口也可以声明常量。


有时在200501之后:

定义:接口是一个无关对象的设备 - 对象

与类层次结构无关 - 可以用来互相交换

。一个对象可以实现多个接口。


复杂而复杂。请注意它使用的单词a ?? devicea ??。


目前的教程(截至2006-08-14)教程
http://java.sun.com/docs/books/tutor ... ... ndI / index.html

界面没有特别给定定义。


参考文献:

Java lang spec,第2版,8.4.2关于方法签名,
http://java.sun.com/docs/books/jls/s...doc.html#38649

1.5.0的官方Java文档页面,它自称为API。
http://java.sun.com/j2se/1.5.0/docs/...w-summary.html


------------

这篇文章存档于:
http://xahlee.org/java-a-day/interface.html


Xah
xa*@xahlee.org

a ?? http://xahlee.org/

On Java''s Interface

Xah Lee, 20050223

In Java the language, there''s this a keyword a??interfacea??.

In a functional language, a function can be specified by its name and
parameter specs. For example:
f(3)
f(3, [9,2])
f("some string")

are usage examples of 3 functions all having the same name, but having
different number and type of arguments. In this way, a function is
essentially known to outsiders by its name and parameter specs. The
gist in this concept is that the user don''t need to know the
implementation details of the function. All she needs to know is the
function''s name, and parameter specs and return value spec. (and of
course what the function is supposed to do.) In this way, interface
and implementation are separated. The implementation can change or
improve anytime, and users don''t need to know.

In Java, the above concept of function name and parameter spec is
called a method''s signature.

For another example, usually a program needs to talk to another
software such as a database software. The database software may have a
set of functions for the purpose of communicating to other software.
In essence, making the database useful to other software. Such a list
of function spec is often called API, which stands for Application
Programing Interface.

The API terminology is abused by the marketing-loving Sun Microsystems
by calling the Java language''s documentation as a??The Java APIa??, even
though Java the language and its paraphernalia of libraries and
hardware-emulation system (all together jargonized as a??the Java
Platforma??) isn''t a Application nor Interface. (a API implies that
there are two disparate entities involved, which are allowed to
communicate thru it. In the case of a??The Java APIa??, it''s one entity
talking to itself.).

In general, the interface concept in programing is a sort of
specification that allows different entities to call and make use of
the other, with the implication that the caller need not know what''s
behind the facade.

In the Object Oriented Programing Paradigm, a new concept arose, that
is the a??interfacea?? aspect of a class.

As we''ve seen, a function has parameter spec that is all there it is a
user needs to know for using it. In Java, this is the method''s
a??signaturea??. Now, as the methodology of the OOP experience multiplies,
it became apparent that the interface concept can be applied to
Classes as well. Specifically: the interface of a class is the class''s
methods.

This concept is then turned into a OOP machinery, in hope of
extracting usefulness in software engineering. That is to say, now in
the Java language, a programer can actually write a piece of code,
whose sole purpose is to define what methods and variables a class
contains. This, is done with the keyword a??interfacea??. Once a interface
is defined, other classes can say which interfaces they implement, so
that if class C implement interface I, then programers don''t need to
know the details about C. All they need to know is the interface I.
(which specifies all the methods, constructors, variables, a class
must have.)

(the Java''s interface, is essentially the a??signaturea?? of a class, in
Java''s own jargon.)

A programer may ask, what''s the big deal anyway? Since in Java,
classes are well documented anyway. What difference does it make to
know the documentation of C versus the documentation of interface for
C?

The thing about interface in Java is that the complexity grows. A Java
interface, can be inherited, just as classes. The idea is that
interfaces can also form a hierarchy just like classes.

In pure OOP such as Java, the object entities used to solve computing
problems are thought to form a relation as of a tree, thus we have the
class hierarchy. In a similar way, it is thought that interface, can
also form a hierarchy fruitfully. A good example is the list data
type. The explanation follows.

In computing languages, often there''s a data concept variously known
as lists, aggregate, sequences, array, vector, tuple, set, matrix,
trees... The basic idea is that it is just a list of things. This list
may not allow repetitions, elements may be lists themselves, may have
certain dimension stipulations (e.g. matrix), may have certain
computational properties such as speed of retrieving a element or
adding a element or memory footprint... etc and so on. Different
requirement and different computational properties have given them
various names to go by. One can however organize them by the interface
perspective. In Java, they are known as Collection, and all have the
interface of Collection. (See http://java.sun.com/j2se/1.5.0/docs/...ollection.html
http://java.sun.com/docs/books/tutor...ces/index.html
)

Consider a Set and List. One does not allow repetitions, while the
other allows. Other than that, both concepts are the same. They both
need methods like adding elements, deleting, inserting, sorting etc.
Therefore, from interface point of view, they share a parent. In Java,
both Set and List are interfaces, inherited from the parent interface
Collection.

So now, in Java, we have two hierarchies of separate category: Classes
and Interfaces. The Classes hierarchy is one single giant tree.
However, the interfaces are not all together as one tree. They are
more like forests, of many trees. It is important to remember that
interfaces and classes are separate entities. A class can implement a
interface. A interface can never inherit from a class.

In Java, it so happens that a class can implement more than one
interfaces. When a class C implements interfaces I1 and I2, C is
guaranteed to have all methods declared by interface I1 and I2. For
example, in Java, class Integer has interfaces Comparable and
Serializable. And the class ArrayList has these interfaces: Cloneable,
Collection, List, RandomAccess, Serializable.

The interface in Java, from a simple useful idea, has mutated into a
incomprehensible complexity.

In Java, Interface is no longer the sole thing a programer needs to
know about a class or function. It is no longer a concept that
separates a function''s user spec from implementation detail.

For example, the ArrayList class has these interfaces: Cloneable,
Collection:List, RandomAccess, Serializable. As one can infer from the
names, they are more about what properties ArrayList has, than a
syntax facade that hides implementation irrelevances.

For example, see the Java documentation on these interfaces: a?¢
interface RandomAccess http://java.sun.com/j2se/1.5.0/docs/...domAccess.html

a?¢ interface Serializable http://java.sun.com/j2se/1.5.0/docs/...ializable.html

a?¢ interface Comparable http://java.sun.com/j2se/1.5.0/docs/...omparable.html

One can see that these a??interfacesa?? are really not interface in
nature, but properties. One might ask, in a??interfacesa?? suchas
RandomAccess that doesn''t have a single variable or method, in what
technical definition that a class is said to satisfy such interfaces?
And, given the existence of these property-like interfaces, can a
programer define their own arbitrary computational property contract?
For example, suppose i want a property ConstantTime for the classes in
game i''m developing. Once i declared a class to have a??interfacea??
ConstantTime, apparently my class is not going to magically become
constant time. How do i define arbitrary properties to the compiler,
and how''s the compiler going to check? The following are the answers.
20050224

Java''s Interface has mutated so much from the interface concept that
it also functions as a pure label. If a interface does not have any
variables or methods, any class can declare it as a interface. There
is no restraint whatsoever. For example, the RandomAccess interface in
Java does not have any variables or methods. Any class can declare it
as a interface, randomly accessible or not. When interface is used as
a label, it is called a a??marker interfacea?? by the Java documentation.
For example, see http://java.sun.com/j2se/1.5.0/docs/...domAccess.html

Because the multi-inheritance nature of Java interface, and its double
role as a label, it no longer function as a communication facade that
is the meaning of interface. If a Java class have interfaces A, B, C,
D, E, one cannot be sure just exactly what methods or variables the
class have. (it will be a union of them, and some of them do not serve
any function with respect to the language.) Further, using interface
as a inert label to indicate computational properties (e.g.
RandomAccess) is a egregious incompetence in the design of a language
for computation. The gist of the problem is that it is a piece of
mathematical irrelevance in the language. As a labeling mechanism in a
language, for the possible benefit from the software engineering
perspective, then it should not be designed as part of the Class
Interface, since labeling and programing interfaces are semantically
disparate.
On the Inanity of Standard Java Tutorials

The standard Java tutorials out there are often inane, in that none of
them actually tried to teach what the language actually manifestly do,
but instead, often talk in some purportedly good engineering
perspective.

For a incomprehensible metaphysical intro to interface using bicycle,
see this page of the Official Java Tutorial:
http://java.sun.com/docs/books/tutor...interface.html.
For a more detailed account of Interface using baffling financial
stocks, see this page of the Official Java Tutorial:
http://java.sun.com/docs/books/tutor...interface.html.
(the official Java Tutorial has went into major changes in 2006. For
the version of the above two pages, see local copy as of 2005

PS the official Java tutorial thru its update history has changed its
stance about what''s a interface:

before 2005:
Definition: An interface is a named collection of method definitions
(without implementations). An interface can also declare constants.

sometimes after 200501:
Definition: An interface is a device that unrelated objects -- objects
that are not related by class hierarchy -- can use to interact with
each other. An object can implement multiple interfaces.

Complexer and complexer. Note its use of the word a??devicea??.

In its current incarnation (as of 2006-08-14) of the tutorial
http://java.sun.com/docs/books/tutor...ndI/index.html,
interface is not particularly given a definition.

References:
Java lang spec, 2nd ed, 8.4.2 on Method Signature,
http://java.sun.com/docs/books/jls/s...doc.html#38649
Official Java documentation page for 1.5.0, where it calls itself API.
http://java.sun.com/j2se/1.5.0/docs/...w-summary.html

------------
This post is archived at:
http://xahlee.org/java-a-day/interface.html

Xah
xa*@xahlee.org
a?? http://xahlee.org/

推荐答案

否。

No.


Xah Lee写道:
Xah Lee wrote:

在函数式语言中,函数可以通过其名称指定,
In a functional language, a function can be specified by its name and



您确定知道什么是函数式语言吗?是?

Are you sure you know what a "functional language" is?


参数规格。例如:

f(3)

f(3,[9,2])

f(" some string")
parameter specs. For example:
f(3)
f(3, [9,2])
f("some string")



这不是真正的典型功能语言的语法。对于

示例,LISP具有函数名称和函数名称。作为列表的元素。 (有些人可能会争辩说,LISP并不是一种功能性语言。)


另外,既然你在评论Java,你应该使用类Java"语法

而不是[9,2]。什么是[9,2]打算代表什么?

整数的范围从9减少到2(含)?

This is not really "typical" syntax for a functional language. LISP, for
example, has the "function name" as an element of a list. (Some might argue
that LISP isn''t exactly a functional language.)

Also, since you are commenting on Java, you should use "Java-like" syntax
rather than "[9,2]". What is "[9,2]" intended to represent? The range of
integers decreasing from 9 to 2, inclusive?


另一个例子,通常一个程序需要与另一个程序交谈/>
软件,如数据库软件。
For another example, usually a program needs to talk to another
software such as a database software.



有趣地使用软件一词​​。

Interesting use of the word "software".


本质上,使数据库对其他软件。
In essence, making the database useful to other software.



这不是句子。

This is not a sentence.


这样的函数规范列表通常称为API,代表申请

编程接口。
Such a list of function spec is often called API, which stands for Application
Programing Interface.



一个API

"an API"


API术语被爱好营销的Sun Microsystems滥用<通过将Java语言的文档称为Java APIa,甚至是

,虽然Java是Java语言及其库的设备和

硬件仿真系统(所有这些一起被称为Java?

Platforma ??)不是应用程序或接口。 ([原文] API暗示

涉及两个不同的实体,允许

通过[原文如此]进行通信。 Java APIa ??,它是一个实体

与自己交谈。)。
The API terminology is abused by the marketing-loving Sun Microsystems
by calling the Java language''s documentation as a??The Java APIa??, even
though Java the language and its paraphernalia of libraries and
hardware-emulation system (all together jargonized as a??the Java
Platforma??) isn''t a Application nor Interface. (a [sic] API implies that
there are two disparate entities involved, which are allowed to
communicate thru [sic] it. In the case of a??The Java APIa??, it''s one entity
talking to itself.).



这在每个事实细节中都是错误的。在博览会的中间(营销爱好,行话化)评论社论的内容是什么?

这有助于解释概念,即使它可以通过

证据支持吗?


Sun称API文档为Java API文档,而不是Java

API",而不是语言文档,API确实是一个界面。

API不一定是,而且通常不是,一个应用程序 - 是一个

应用程序绝不是API的一部分。为什么你在世界上做了什么?b $ b大写应用程序和接口?


它是API,而不是API。它是通过,而不是通过。


关于API的声明。与两个完全不同的实体有关使得

毫无意义。在API中肯定没有任何东西可以表征为一个实体与自己交谈。什么是实体你有没有想过参与?

This is incorrect in every factual detail. And what''s with the editorial
comment in the middle of the exposition ("marketing-loving", "jargonized")?
How does that help explain the concepts, even if it were supportable by the
evidence?

Sun calls the API documentation "the Java API documentation", not "the Java
API", and not the language documentation, and the API is indeed an interface.
An API need not be, and quite often is not, an application - being an
application is in no wise part of being an API. And why in the world did you
capitalize "Application" and "Interface"?

It''s "an API", not "a API". It''s "through", not "thru".

The statement about an "API" having to do with "two disparate entities" makes
no sense. There is certainly nothing in the API that one can characterize as
"one entity talking to itself". What "entities" do you imagine are involved?


一般来说,编程中的接口概念是一种允许不同实体调用的b / b
规范另一个[原文如此]使用

,暗示调用者不需要知道幕后的'b
'。
In general, the interface concept in programing is a sort of
specification that allows different entities to call and make use of
the other [sic], with the implication that the caller need not know what''s
behind the facade.



另一个没有前提,你还没有定义实体,

和这个词"接口"具有许多含义通常......在

编程中。你应该专注于Java的意思(和你的语法)。

There is no antecedent for "the other", and you haven''t defined "entities",
and the word "interface" has a number of meanings "in general ... in
programming". You should focus on the Java meaning (and your grammar).


在面向对象的编程范例[原文如此]中,出现了一个新的概念,即

是a ??界面??一个方面的课程。
In the Object Oriented Programing Paradigm [sic], a new concept arose, that
is the a??interfacea?? aspect of a class.



需要历史引文。接口不是类的一个方面。

Historical citation needed. And an interface is not an "aspect of a class".


正如我们所见,一个函数有参数spec [sic]就在那里[原文如此]用户需要知道使用它。在Java中,这是方法''

a ?? signaturea ??。现在,随着OOP经验的方法论的增加,

显然界面概念也可以应用于

类。具体来说:类的接口是类的'

方法。
As we''ve seen, a function has parameter spec [sic] that is all there it [sic] is a
user needs to know for using it. In Java, this is the method''s
a??signaturea??. Now, as the methodology of the OOP experience multiplies,
it became apparent that the interface concept can be applied to
Classes as well. Specifically: the interface of a class is the class''s
methods.



好​​的,我已经受够了。我会说你需要一个好的编辑器来清理语法,

但是你所拥有的只是一个更好的错误解释。


- Lew

OK, I''ve had enough. I''d say you need a good editor to clean up the grammar,
but then all you''d have is a better-written incorrect explanation.

-- Lew


不要喂这些巨魔:-)

Don''t Feed The Trolls :-)


这篇关于在Java的接口上(计算机编程中接口的含义)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆