Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 哪种设计模式(复合?)用于将数据收集到单个文档中?_C#_Design Patterns - Fatal编程技术网

C# 哪种设计模式(复合?)用于将数据收集到单个文档中?

C# 哪种设计模式(复合?)用于将数据收集到单个文档中?,c#,design-patterns,C#,Design Patterns,在操作流程的末尾,有一个打印模块,该模块从涉及的各种来源(客户、订单标题、订单内容、用户、付款等)收集数据,以生成摘要收据或报告打印输出。要将数据传递到此模块,适当的模式应该是什么 在现有代码中,传递的数据如下: Print print = new Print(); // then a very long list of info print.PaymentInfo1 = ...; print.PaymentInfo2 = ...; print.CustomerInfo1 = ...; ...

在操作流程的末尾,有一个打印模块,该模块从涉及的各种来源(客户、订单标题、订单内容、用户、付款等)收集数据,以生成摘要收据或报告打印输出。要将数据传递到此模块,适当的模式应该是什么

在现有代码中,传递的数据如下:

Print print = new Print();

// then a very long list of info
print.PaymentInfo1 = ...;
print.PaymentInfo2 = ...;
print.CustomerInfo1 = ...;
...

// Then I print
print.PrintReceipt();
其思想是将各种对象聚集在一个实体中。我已经看到了复合模式、外观和模块模式。哪种模式最适合

我想的是:

Print print = new Print();

// then only the sources involved
print.AddPayment(currPayment);
print.AddCustomer(currCustomer);
...

// Then I print
print.PrintReceipt();

发布更多代码。现在很难理解你想做什么。谁来决定打印的方式(例如,付款的样子等)?是打印机还是付款?访问者模式可能会解耦此依赖关系。对于存储数据,我看不出将实体存储在单个(已排序的)集合(或可能是每个类型的集合)中有什么错。printer类通过使用现有代码从例如payment、customer等处获取一条信息来管理打印输出的布局,问题是信息列表很长,会影响可读性。第二个问题是打印类是从应用程序中的另一个进程用于另一种类型的收据(不同的数据集)@NicoSchertler我没有看到任何层次结构-访问者正在用原子弹杀死蚊子。请发布更多代码。现在很难理解你想做什么。谁来决定打印的方式(例如,付款的样子等)?是打印机还是付款?访问者模式可能会解耦此依赖关系。对于存储数据,我看不出将实体存储在单个(已排序的)集合(或可能是每个类型的集合)中有什么错。printer类通过使用现有代码从例如payment、customer等处获取一条信息来管理打印输出的布局,问题是信息列表很长,会影响可读性。第二个问题是打印类是从应用程序中的另一个进程用于另一种类型的收据(不同的数据集)@NicoSchertler我没有看到任何层次结构-访问者正在用原子弹杀死一只蚊子。