using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleFactory
{
class Program
{
#region 支付类
// 支付接口
public interface IPay
{
void Order(); // 下单;
}
// 微信支付 继承 支付接口
public class WechatPay : IPay
{
// 实现下单动作
public void Order()
{
Console.WriteLine("微信支付、统一下单");
}
}
// 阿里支付 继承 支付接口
public class AliPay : IPay
{
// 实现下单动作
public void Order()
{
Console.WriteLine("阿里支付、统一下单");
}
}
#endregion
#region 支付工厂类
public class SimplePayFactory
{
public static IPay CreratPay(string strPayType)
{
if (strPayType == "")
{
return null;
}
// 根据支付类型 返回不同的类
switch (strPayType)
{
case "ali":
return new AliPay();
case "wechat":
return new WechatPay();
default:
return new AliPay();
}
}
}
#endregion
static void Main(string[] args)
{
// 使用ali支付
IPay aliPay = SimplePayFactory.CreratPay("ali");
aliPay.Order();
// 使用微信支付
IPay wechartPay = SimplePayFactory.CreratPay("wechat");
wechartPay.Order();
Console.ReadLine();
}
}
}