我们什么时候使用接口扩展接口 [英] When do we use interface extends interface

查看:109
本文介绍了我们什么时候使用接口扩展接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道何时可以使用扩展另一个接口的接口。我想知道一个实际的例子,当我们使用它时。

I wish to know when we can use an interface extending another interface. I wish to know a practical example and when we use it.

推荐答案

当子接口提供超级接口提供的所有内容时扩展接口,并做一些重要的事情。例如, SortedMap< K,V> 实现 Map< K,V> ,因为有序地图是一张地图支持地图的所有操作,以及一些仅适用于有序地图的操作。

You extend an interface when a subinterface provides everything the superinterface provides, and does something else of importance. For example, SortedMap<K,V> implements Map<K,V>, because sorted map is a map that supports all operations of a map, plus some operations applicable only to sorted maps.

这类似于在类之间继承,但它允许多个实现。例如,可以将 SortedMap 实现为键的排序列表加上并行的值数组,而不是树。这将允许用户交换更快或更优越的实现,而无需更改其余代码。换句话说,接口之间的继承允许您保留编程到接口的好处。

This is similar to inheriting among classes, but it allows for multiple implementations. For example, one could implement a SortedMap as a sorted list of keys plus a parallel array of values, rather than a tree. This would let users swap in a faster or otherwise superior implementation without changing the rest of the code. In other words, inheritance among interfaces lets you preserve the benefits of programming to interfaces.

这篇关于我们什么时候使用接口扩展接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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