Design patterns 真实世界的外观(C#)
示例
public class MyDataExporterToExcell{
public static void Main()
{
GetAndExportExcelFacade facade = new GetAndExportExcelFacade();
facade.Execute();
}
}
public class GetAndExportExcelFacade
{
// 以下所有服务均自行执行操作,确定数据位置,
// 获取数据,格式化数据并导出数据
private readonly DetermineExportDatabaseService _determineExportData = new DetermineExportDatabaseService();
private readonly GetRawDataToExportFromDbService _getRawData = new GetRawDataToExportFromDbService();
private readonly TransformRawDataForExcelService _transformData = new TransformRawDataForExcelService();
private readonly CreateExcelExportService _createExcel = new CreateExcelExportService();
// 外墙将所有单独的部分放在一起,作为其单一责任。
public void Execute()
{
var dataLocationForExport = _determineExportData.GetDataLocation();
var rawData = _getRawData.GetDataFromDb(dataLocationForExport);
var transformedData = _transformData.TransformRawToExportableObject(rawData);
_createExcel.GenerateExcel("myFilename.xlsx");
}
}
以上是 Design patterns 真实世界的外观(C#) 的全部内容, 来源链接: utcz.com/z/326290.html