package com.yanek.test;
public interface UserManager {
public abstract void addUser();
}
package com.yanek.test;
public class UserManagerImpl implements UserManager {
public void addUser() {
System.out.println("hello world!");
}
}
package com.yanek.test;
public class UserManagerFactory {
private static UserManager userManager;
private UserManagerFactory()
{
}
public synchronized static UserManager getInstance()
{
if (!initialized)
doInitialize();
return userManager;
}
private static boolean initialized = false;
private static synchronized void doInitialize()
{
if (!initialized)
{
userManager = new UserManagerImpl();
initialized = true;
}
}
/**
* @param args
*/
public static void main(String[] args) {
UserManager um1=UserManagerFactory.getInstance();
UserManager um2=UserManagerFactory.getInstance();
UserManager um3=UserManagerFactory.getInstance();
System.out.println("um1="+um1);
System.out.println("um2="+um2);
System.out.println("um3="+um3);
um1.addUser();
um2.addUser();
um3.addUser();
}
}