实现实例化的三个步骤:
// 1、 构造函数私有化
private InstanceOfClient() {
}
// 2、 定义静态的当前类引用的属性
private static InstanceOfClient ioc;
// 3、定义静态函数 用户获取对象
public static synchronized InstanceOfClient newInstance() {
if (ioc == null) {
ioc = new InstanceOfClient();
}
return ioc;
}
}
之后便可以通过调用这个实例来调取他所拥有的属性以及对象,而不用来回的传参,也避免了不必要的麻烦,甚至是出现在传参过程中可能会出现的问题!