import java.util.Random;
abstract class UiData
{
public void DoLogic()
{
Random pRandom = new Random();
m_iData = pRandom.nextInt(100);
pRandom = null;
}
public abstract void DoView();
protected int m_iData;
}
class UiView_480_272 extends UiData
{
@Override
public void DoView()
{
System.out.println("View 480 * 272: "+m_iData);
}
}
class UiView_320_240 extends UiData
{
@Override
public void DoView()
{
System.out.println("View 320 * 240: "+m_iData);
}
}
class UiView_NUM extends UiData
{
@Override
public void DoView()
{
System.out.println("Dos: "+m_iData);
}
}
abstract class UiFactory
{
public abstract <T extends UiData> T GetUi(Class<T> c);
}
class CE600_UiFactory extends UiFactory
{
@SuppressWarnings({ "finally", "unchecked" })
@Override
public <T extends UiData> T GetUi(Class<T> c)
{
// TODO Auto-generated method stub
UiData pUiData = null;
try
{
pUiData = (UiData)Class.forName(c.getName()).newInstance();
}
catch( Exception e)
{
throw e;
}
finally
{
return (T)pUiData;
}
}
}
class DOS_UiFactory extends UiFactory
{
@SuppressWarnings({ "finally", "unchecked" })
@Override
public <T extends UiData> T GetUi(Class<T> c)
{
// TODO Auto-generated method stub
UiData pUiData = null;
try
{
pUiData = new UiView_NUM();
}
catch( Exception e)
{
throw e;
}
finally
{
return (T)pUiData;
}
}
}
//---------------------------------------------------
class FactoryClient
{
public static void Client()
{
UiFactory pUiFactoryView = new CE600_UiFactory();
UiData pUiData1 = pUiFactoryView.GetUi(UiView_480_272.class);
pUiData1.DoLogic();
pUiData1.DoView();
pUiData1 = null;
UiData pUiData2 = pUiFactoryView.GetUi(UiView_320_240.class);
pUiData2.DoLogic();
pUiData2.DoView();
pUiData2 = null;
pUiFactoryView = null;
UiFactory pUiFactoryDos = new DOS_UiFactory();
UiData pUiDataDos = pUiFactoryDos.GetUi(UiView_320_240.class);
pUiDataDos.DoLogic();
pUiDataDos.DoView();
pUiDataDos = null;
pUiFactoryView = null;
}
}