接口的功能描述? [英] Description of what an Interface does?

查看:395
本文介绍了接口的功能描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于OOP,您如何描述界面?

With regards to OOP,how would you describe an interface?

我的意思是的,子分类可以描述为Has-A,继承可以是Is-A。
成员方法可以是Can-Do..

What i mean is , sub-classing can be described as "Has-A" and Inheritance could be "Is-A". A member method could be "Can-Do" ..

有没有什么方法可以扩展(没有双关语)来描述接口的作用?

Is there any way this could be extended (no pun intended) to describe what an Interface does?

谢谢

推荐答案

我认为对象为名词,方法为动词,接口为形容词(当然这个类比过于简单,但经常运作得很好)。

I think of objects as nouns, methods as verbs, and interfaces as adjectives (of course this analogy is oversimplified, but frequently works well enough).

示例:接口 Serializable 的工作方式类似于形容词,因为它将一些特性应用于实现该接口的对象,但不会更改那个对象是。我们可以说,这是一个可序列化的对象。但是我们没有说,这个对象可序列化的,我们也不说,这个对象有一个可序列化的。

Example: an interface Serializable works like an adjective, in that it applies some qualities to an object that implement that interface, but does not change what that object is. We can say, "this is a serializable object." But we don't say, "this object is a serializable," nor do we say, "this object has a serializable."

我也很喜欢Federico的回答接口是CAN-DO。

I also like Federico's answer that an interface is "CAN-DO".

接口是该类支持的一组相关操作。接口中的方法一起描述了类可以做什么。

An interface is a group of related operations that the class supports. Together, the methods in an interface describe what the class can do.

就像名词可以采用多个形容词一样,一个类可以实现多个接口,只要它们不要没有冲突。类实现的所有接口的并集是类可以执行的操作的总和。

Just like a noun can take multiple adjectives, a class can implement multiple interfaces, as long as they don't conflict. The union of all the interfaces a class implements is the sum of what the class can do.

实际上,接口是一组方法签名,没有代码实施这些方法。只是方法名称和参数。根据语言的不同,方法签名也可能包括返回类型和抛出的异常。

In practical terms, an interface is a set of method signatures, without the code implementing those methods. Just the method name and arguments. Depending on the language, a method signature may also include return type, and exceptions thrown.

接口由方法组成,但不包含数据成员。

An interface consists of methods, but not data members.

BTW,我不会说子类别是HAS-A。我的理解是子类与继承相同,所以这些都是IS-A。而HAS-A被称为聚合或组合。

BTW, I wouldn't say sub-classing is HAS-A. My understanding is that sub-classing is the same as inheritance, so these are both IS-A. Whereas HAS-A is called Aggregation or Composition.


  • 组合是对象拥有另一个对象的地方。摧毁外部物体也会破坏内部物体。示例:大学组成部门。关闭大学,部门消失。

  • Composition is where an object owns another object. Destroying the outer object also destroys the inner objects. Example: University composes Departments. Close the University, and the Departments disappear.

聚合是对象包含另一个对象但不拥有它的地方。销毁外部对象不会破坏内部对象。示例:大学雇用教授,但关闭大学不会杀死教授。

Aggregation is where an object includes another object, but does not own it. Destroying the outer object does not destroy the inner objects. Example: University employs Professors, but closing the University does not kill the Professors.

这篇关于接口的功能描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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