标签:null 分享 instance 好的 blog erp 安全 提供者 shm
举例如下:
1 public static Boolean valueof(boolean a){ 2 return a?Boolean.TRUE:Boolean.FALSE; 3 }
举例如下:
1 public interface Service{ 2 //service-specific methods go here 3 } 4 5 public interface Provider{ 6 Service newService(); 7 } 8 9 public class Services{ 10 private Services(){} 11 12 private static final Map<String, Provider> providers=new ConcurrentHashMap<String, Provider>(); 13 public static final String DEFAULT_PROVIDER_NAME="<def>"; 14 15 //provider registration API 16 public static void registerDefaultProvider(Provider p){ 17 registerProvider(DEFAULT_PROVIDER_NAME, p); 18 } 19 public static void registerProvider(String name,Provider p){ 20 providers.put(name, p); 21 } 22 23 //service access API 24 public static Service newInstance(){ 25 return newInsance(DEFAULT_PROVIDER_NAME); 26 } 27 public static Service newInsance(String name){ 28 Provider provider= providers.get(name); 29 if(provider==null){ 30 throw new IllegalArgumentException("No provider registered with name:"+ name); 31 } 32 return provider.newService(); 33 } 34 } 35
标签:null 分享 instance 好的 blog erp 安全 提供者 shm
原文地址:http://www.cnblogs.com/dmir/p/6758189.html