English 中文(简体)
1. 启动接口?
原标题:Initializing an Interface?
最佳回答

骗局是认识到,你不再“进行”、“证实”或“开始”接口。 你只是把变数定义为你知道如何实施这一接口。

你基本上告诉从事这一守则工作的其他方案人员,就这一方法的其余部分而言,你只关心以下事实:myDoc(即符合的>Doc(即:符合Doc接口的内容)。 这将使方案拟定更加简单,因为民主选举学会的汽车编造现在只能显示这一接口界定的方法,而不是<代码”的所有方法。 简单的Doc能够做到。

想象,今后你希望扩大你的职能范围,以便你能够根据某些投入,执行《多奇》。 你们说的是,不是要明确提出简单明了的,而是:

Doc mydoc = docFactory.getByType(inputType);

<代码>docFactory 可产生任何类型的Doc,而且这一方法实际上并未照顾到何种瞬时发生,因为它将视之为Doc

问题回答

您不能建立接口,你在此做的是,你创设了一个标的<条码>:mydoc。 简单的Doc,实施接口Doc。 由于这几类人安装了这一接口,因此,允许你处理<密码>mydoc,如它是该接口的一个实例。 这使你能够查阅接口中所有已申报的方法,这些方法在<代码>栏中实施。 简明/代码

举例来说,如果您的“三面”能够考虑:

public interface Doc {
    void print();
}

页: 1 简单 多奇阶层希望:

public class SimpleDoc implements Doc {

    public void clear() { ... }

    @Override
    public void print() { ... }

}

......你只能查阅以下网址:www.c.org/index.html。 但也可以说:

SimpleDoc mydoc = new SimpleDoc();

... and then you would be also able to call clear()





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签