oop - MVC : Differences Between Two-Step and Composite View Patterns

标签 oop model-view-controller design-patterns

简单来说,您能告诉我“两步 View ”和“复合 View ”布局设计模式之间的区别吗?

最佳答案

Composite View顾名思义,是 Composite (如 GOF 模式中)的 View 。这意味着复合 View 是其他(复合、 TemplateTransform 、…) View 的树形结构,您可以通过根复合 View 对象统一处理。

Composite View UML

如果客户端分派(dispatch)到根View,它将分派(dispatch)到树结构中的所有View,从而创建结果页面。因此,在复合 View 中,没有两个步骤,而只有一个步骤,因为每个单独的 View 都是一个单步 View (具体的最终输出)。

Use Composite Views that are composed of multiple atomic subviews. Each subview of the overall template can be included dynamically in the whole, and the layout of the page can be managed independently of the content.

简化的伪代码:

composite = new CompositeView;
composite.add(new HeaderView(headerData));
composite.add(new TableView(tableData));
…
composite.add(new FooterView(footerData));
composite.render();

这与 Two-Step-View 不同因为两步 View 不是复合的,而只是执行的两个步骤,首先从域数据到该数据的逻辑屏幕表示,然后到具体的输出格式。也就是说,它将页面的逻辑结构和格式分开。

TwoStepView UML

Two Step View deals with this problem by splitting the transformation into two stages. The first transforms the model data into a logical presentation without any specific formatting; the second converts that logical presentation with the actual formatting needed.

简化的伪代码:

twoStepView = new TwoStepView;
twoStepView.setData(data);
twoStepView.setFirstStep(new ConcreteScreen);
twoStepView.setSecondStep(new ConcreteHtmlScreen);
twoStepView.transform();

如您所见,两步 View 仅协调这两个步骤。例如,如果您的两步 View 使用 XSLT,它只会处理从输入 XML 到屏幕 XML 再到最终 HTML 输出的转换。 Concrete Screen 和 ConcreteHTMLScreen 将成为 XSLT 模板。

关于oop - MVC : Differences Between Two-Step and Composite View Patterns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13578312/

相关文章:

javascript - nodejs并行回调设计模式

matlab - 在matlab中使用FFT去除图像中的图案和噪声

java - 值对象模式和数据传输模式之间的区别

java - 使用字符串在文本文件中保存联系人时出现问题

java - 匿名对象的 Scala 语法

php - 在非对象上调用成员函数 fetchAll()

model-view-controller - ASP.NET MVC : Nesting ViewModels within each other, 反模式与否?

javascript - 如何Javascript切换运行时生成的div的ID

c# - 如何使用类(带有类列表)作为数据库,使用 MVC5 创建/索引操作

javascript - JavaScript 中接口(interface)模式的运行示例或工作演示