想检查这是否是表示抽象工厂模式的好例子.这是主题戴尔(工厂)制造xps(产品)戴尔(工厂)制造灵感(产品)惠普(工厂)使特使(产品)惠普(工厂)制造presario(产品)
BestBuy销售电脑.
//Abstract factory
abstract class ComputerFactory
{
public abstract Computer BuildComputer(Computer.ComputerType compType);
}
//Concrete factory
class Dell : ComputerFactory
{
public override Computer BuildComputer(Computer.ComputerType compType)
{
if (compType == Computer.ComputerType.xps)
return (new xps());
else if (compType == Computer.ComputerType.inspiron)
return new inspiron();
else
return null;
}
}
//Concrete factory
class Hp : ComputerFactory
{
public override Computer BuildComputer(Computer.ComputerType compType)
{
if (compType == Computer.ComputerType.envoy)
return (new envoy());
else if (compType == Computer.ComputerType.presario)
return new presario();
else
return null;
}
} …Run Code Online (Sandbox Code Playgroud)