/// <summary>
/// 子系统中的一个类
/// </summary>
public class SubSystemOne
{
public void MethodeOne()
{
Console.WriteLine("Sub System first method.");
}
}
/// <summary>
/// 子系统中一个类
/// </summary>
public class SubSystemTwo
{
public void MethodTwo()
{
Console.WriteLine("Sub System second method.");
}
}
/// <summary>
/// 子系统中一个类
/// </summary>
public class SubSystemThree
{
public void MethodThree()
{
Console.WriteLine("Sub System third method.");
}
}
/// <summary>
/// 子系统中一个类
/// </summary>
public class SubSystemFour
{
public void MethodFour()
{
Console.WriteLine("Sub System fourth method.");
}
}
/// <summary>
/// 外观类
/// </summary>
public class Facade
{
private SubSystemOne one;
private SubSystemTwo two;
private SubSystemThree three;
private SubSystemFour four;
public Facade()
{
one = new SubSystemOne();
two = new SubSystemTwo();
three = new SubSystemThree();
four = new SubSystemFour();
}
public void MethodA()
{
Console.WriteLine("\nMethod group A----");
one.MethodeOne();
two.MethodTwo();
four.MethodFour();
}
public void MethodB()
{
Console.WriteLine("\nMethod group B----");
two.MethodTwo();
three.MethodThree();
}
}
class Program
{
static void Main(string[] args)
{
// 由于Facade的作用,客户端可以根本不知道子系统类的存在
Facade facade = new Facade();
facade.MethodA();
facade.MethodB();
Console.Read();
}
}
public class Employee
{
public string Name { get; set; }
public int Age { get; set; }
public Salary Salary { get; set; }
}
public class Salary
{
public DateTime From { get; set; }
public DateTime To { get; set; }
public decimal Amount { get; set; }
}
public class EmployeeDataAccess
{
public void SaveEmployee(Employee employee)
{
Console.WriteLine("Save employee to database.");
}
public void DeleteEmployee(Employee employee)
{
Console.WriteLine("Remode employee from database.");
}
}
public class SalaryDataAccess
{
public void SaveSalary(Salary salary)
{
Console.WriteLine("Save salary to database.");
}
public void DeleteSalary(Salary salary)
{
Console.WriteLine("Remove salary from database.");
}
}
/// <summary>
/// DataAccess为客户端提供一个简单的接口
/// </summary>
public class DataAccess
{
private EmployeeDataAccess employeeDataAccess = new EmployeeDataAccess();
private SalaryDataAccess salaryDataAccess = new SalaryDataAccess();
public void SaveEmployee(Employee employee)
{
// 先保存员工基本信息
employeeDataAccess.SaveEmployee(employee);
// 保存员工薪水信息
salaryDataAccess.SaveSalary(employee.Salary);
}
public void RemoveEmployee(Employee employee)
{
// 先删除员工薪水信息
salaryDataAccess.DeleteSalary(employee.Salary);
// 删除员工基本信息
employeeDataAccess.DeleteEmployee(employee);
}
}
class Program
{
static void Main(string[] args)
{
DataAccess.DataAccess dataAccess = new DataAccess.DataAccess();
DataAccess.Employee employee = new DataAccess.Employee() { Salary = new DataAccess.Salary(), Name = "Wang Kevin", Age = 22 };
dataAccess.SaveEmployee(employee);
dataAccess.RemoveEmployee(employee);
Console.Read();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有