抽象工厂简单实现
正在做一个项目的设计,想用点设计思想,就用了最简单的工厂模式,不太会用,感觉一头雾水,仿照这别人的例子作了一个,主要业务就是做一个验证,根据不同的服务类别产生不同的验证逻辑,对于服务分为四个大类,每一类对应几个服务类型。
名字取得乱七八糟的。设计时主要考虑根据不同的服务类别返回不同的验证类。有点乱。
名字取得乱七八糟的。设计时主要考虑根据不同的服务类别返回不同的验证类。有点乱。
public class ServiceCheck
{
public ServiceCheck()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}
public interface IServiceCheck
{
bool CheckServiceInput();
}
RepairCheck
ExchangeCheck
ThirdServiceCheck
鉴定咨询
public abstract class ServiceFactory
{
public abstract IServiceCheck Creator( string ServiceType );
}
public class RepairFactory : ServiceFactory
{
public override IServiceCheck Creator( string ServiceType )
{
switch( ServiceType )
{
case "T01": return new SellRepairCheck();
case "T08": return new MarkRepairCheck();
case "T09": return new MidRepairCheck();
default: return new SellRepairCheck();
}
}
}
public class ExchangeFactory : ServiceFactory
{
public override IServiceCheck Creator( string ServiceType )
{
switch( ServiceType )
{
case "T01": return new SellRepairCheck();
case "T08": return new MarkRepairCheck();
case "T09": return new MidRepairCheck();
default: return new SellRepairCheck();
}
}
}
public class ThirdServiceFactory : ServiceFactory
{
public override IServiceCheck Creator( string ServiceType )
{
switch( ServiceType )
{
case "T02": return new InstallCheck();
case "T11": return new GetMachineCheck();
case "T12": return new MoveMachineCheck();
case "T14": return new DesignCheck();
case "T15": return new MaintainCheck();
case "T21": return new UserBuyCheck();
case "T99": return new InnerCheck();
default: return new InnerCheck();
}
}
}
public class InquireServiceFactory : ServiceFactory
{
public override IServiceCheck Creator( string ServiceType )
{
switch( ServiceType )
{
case "T03": return new DebugCheck();
case "T06": return new MarkIdentifyCheck();
case "T07": return new MidIdentifyCheck();
case "T10": return new IdentifyCheck();
case "T13": return new AdviceCheck();
default: return new DebugCheck();
}
}
}
{
public ServiceCheck()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}
public interface IServiceCheck
{
bool CheckServiceInput();
}
RepairCheck
ExchangeCheck
ThirdServiceCheck
鉴定咨询
public abstract class ServiceFactory
{
public abstract IServiceCheck Creator( string ServiceType );
}
public class RepairFactory : ServiceFactory
{
public override IServiceCheck Creator( string ServiceType )
{
switch( ServiceType )
{
case "T01": return new SellRepairCheck();
case "T08": return new MarkRepairCheck();
case "T09": return new MidRepairCheck();
default: return new SellRepairCheck();
}
}
}
public class ExchangeFactory : ServiceFactory
{
public override IServiceCheck Creator( string ServiceType )
{
switch( ServiceType )
{
case "T01": return new SellRepairCheck();
case "T08": return new MarkRepairCheck();
case "T09": return new MidRepairCheck();
default: return new SellRepairCheck();
}
}
}
public class ThirdServiceFactory : ServiceFactory
{
public override IServiceCheck Creator( string ServiceType )
{
switch( ServiceType )
{
case "T02": return new InstallCheck();
case "T11": return new GetMachineCheck();
case "T12": return new MoveMachineCheck();
case "T14": return new DesignCheck();
case "T15": return new MaintainCheck();
case "T21": return new UserBuyCheck();
case "T99": return new InnerCheck();
default: return new InnerCheck();
}
}
}
public class InquireServiceFactory : ServiceFactory
{
public override IServiceCheck Creator( string ServiceType )
{
switch( ServiceType )
{
case "T03": return new DebugCheck();
case "T06": return new MarkIdentifyCheck();
case "T07": return new MidIdentifyCheck();
case "T10": return new IdentifyCheck();
case "T13": return new AdviceCheck();
default: return new DebugCheck();
}
}
}