【发布时间】:2015-04-16 15:45:52
【问题描述】:
请看下面的例子。
public interface Testing {
public void go();
}
public class TestingImplements implements Testing {
@Override
public void go() {
}
}
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
Testing throughInterface = new TestingImplements();
TestingImplements directly = new TestingImplements();
}
}
我的问题是, 直接使用 throughInterface 有什么优点和缺点。稍微解释一下会很有帮助。
Testing throughInterface = new TestingImplements();
而不是,
TestingImplements directly = new TestingImplements();
【问题讨论】:
-
这不是奇怪的方式,这是首选方式。
-
你展示的两个例子是一样的(复制+粘贴失败?)
标签: java design-patterns interface