using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FactoryEntiy
{
public interface Ishop
{
double Getrent(int days, double dayprice, double performance);
}
}
using FactoryEntiy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProductEnity
{
/// <summary>
/// 继承商店接口,实现里面的行为方法,即算法
/// </summary>
public class Ashop:Ishop
{
/// <summary>
/// /// A类型商店租金额,天数*单价+绩效*0.005
/// </summary>
/// <param name="days">天数</param>
/// <param name="dayprice">每天单价</param>
/// <param name="performance">日平均绩效</param>
/// <returns></returns>
public double Getrent(int days, double dayprice, double performance)
{
Console.WriteLine("A商店的租金算法");
return days * dayprice + performance * 0.01;
}
}
}
using FactoryEntiy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProductEnity
{
/// <summary>
/// 继承商店接口,实现里面的行为方法,即算法
/// </summary>
public class Bshop:Ishop
{
/// <summary>
/// B类型商店的租金=月份*(每月价格+performance*0.001)
/// </summary>
/// <param name="month">月数</param>
/// <param name="monthprice">月单价</param>
/// <param name="performance">月平均绩效</param>
/// <returns></returns>
public double Getrent(int month, double monthprice, double performance)
{
Console.WriteLine("B商店的租金算法");
return month * (monthprice + performance * 0.001);
}
}
}
using FactoryEntiy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FactoryMethod
{
/// <summary>
/// 工厂类,创建商店类型实体
/// </summary>
public interface IFactory
{
Ishop CreateShop();
}
}
using FactoryEntiy;
using FactoryMethod;
using ProductEnity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProductEnity
{
/// <summary>
/// 继承工厂类,创建A类型商店实体
/// </summary>
public class CreateBshop : IFactory
{
public Ishop CreateShop()
{
return new Ashop();
}
}
}
using FactoryEntiy;
using FactoryMethod;
using ProductEnity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProductEnity
{
/// <summary>
/// 继承工厂类,创建B类型商店实体
/// </summary>
public class CreateAshop : IFactory
{
public Ishop CreateShop()
{
return new Bshop();
}
}
}
using FactoryEntiy;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
namespace FactoryMethod.App
{
class Program
{
static void Main(string[] args)
{
string shopname = ConfigurationManager.AppSettings["CreateShopClassName"];
//shopname为创建商店类名称,此处=CreateAshop
IFactory af = (IFactory)Assembly.Load("ProductEnity").CreateInstance("ProductEnity." + shopname);
//第一个ProductEnity是dll的名称,第二个ProductEnity是项目的命名空间。
Ishop As = af.CreateShop(); double total = As.Getrent(30, 300, 2000); //30 天/100元 日平均绩效为2000
Console.WriteLine("该A类型商店的租金为:" + total);
Console.WriteLine("=============");
IFactory bf = (IFactory)Assembly.Load("ProductEnity").CreateInstance("ProductEnity." + "CreateBshop");
//CreateBshop可以保存为配置或者存在数据库中,
//注意该保存字符串应该与项目中创建的类名一样,
//否则反射的方式会找不到该项目下的类。
Ishop Bs = bf.CreateShop(); total = Bs.Getrent(30, 300, 2000); //30 天/100元 日平均绩效为2000
Console.WriteLine("该A类型商店的租金为:" + total);
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有