摘要:
假设你编写了两个类,一个是人(Person),一个是手机(Mobile)。 人有时候需要用手机打电话,需要用到手机的dialUp方法。 传统的写法是这样: Java code public class Person{ public boolean makeCall(long number){ Mobile mobile=new Mobile(); return mobile.dialUp(number); }}也就是说,类Person的makeCall方法对Mobile类具有依赖,必须手动生成一个新的实例new Mobile()才可以进行之后的工作。... 阅读全文