【實驗內容和要求】spa
有一個OEM製造商代理作HP筆記本電腦(Laptop),後來該製造商獲得了更多的品牌筆記本電腦的訂單Acer,Lenovo,Dell,該OEM商發現,若是一次同時作不少個牌子的本本,有些不利於管理。利用工廠模式改善設計,用JAVA語言實現 (或C#控制檯應用程序實現)該OEM製造商的工廠模式。繪製該模式的UML圖。設計
【模式UML圖】代理
public interface ComputerFactoryblog
{get
public void getComputerType();class
}程序
public class AcerFactory implements ComputerFactoryim
{top
public void getComputerType()img
{
return new AcerFactory;
}
}
public class DellFactory implements ComputerFactory
{
public void getComputerType()
{
return new DellFactory;
}
}
public class LenovoFactory implements ComputerFactory
{
public void getComputerType()
{
return new LenovoFactory;
}
}
public interface Computer
{
public void computerType();
}
public class Acer implements Computer
{
public AcerFactory computerType()
{
return "Acer";
}
}
public class Dell implements Computer
{
public DellFactory computerType()
{
return "Dell";
}
}
public class Lenovo implements Computer
{
public LenovoFactory computerType()
{
return "Lenovo";
}
}