MVC:两步和复合视图模式之间的差异 [英] MVC: Differences Between Two-Step and Composite View Patterns

查看:172
本文介绍了MVC:两步和复合视图模式之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单来说,您能否告诉我两步查看和复合视图布局设计模式之间的区别?

解决方案

,因为两步视图不是复合,而只是执行的两个步骤,首先从域数据到逻辑屏幕表示数据然后到具体的输出格式。也就是说,它分离了页面的逻辑结构和格式。




Two Step View通过将转换分为两个阶段来处理此问题。首先将模型数据转换为逻辑表示,而不需要任何特定的格式化;第二个将所需的实际格式转换为逻辑表示。


简化的伪代码:

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

您可以看到,两步视图只是协调两个步骤。例如,如果您的Two-Step-View使用XSLT,则只处理从输入XML到Screen XML到最终HTML输出的转换。混凝土屏幕和混凝土HTMLScreen将是XSLT模板。


In simple terms, could you please tell me the difference between the "Two-Step View" and "Composite View" Layout Design Patterns?

解决方案

Composite View, as the name implies, is a Composite (as in the GOF pattern) of Views. That means the Composite View is a tree structure of other (Composite, Template, Transform, …) Views, which you can handle uniformly through the root Composite View object.

If the client dispatches to the root View, it will dispatch to all the Views in the tree structure, thereby creating the result page. So in Composite Views, there is not two steps, but just one, because each individual View is a one-step View (of the concrete final output).

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.

In simplified Pseudo-Code:

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

This is different from Two-Step-View in that the Two-Step-View is not a Composite, but just two steps of execution, first from Domain Data to a logic screen representation of that data and then to the concrete output format. That is, it separates logic structure and formatting of the page.

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.

In simplified Pseudo-Code:

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

As you can see, the Two-Step-View is only orchestrating the two steps. For instance, if your Two-Step-View uses XSLT, it would only handle the transformation from the input XML to the Screen XML to the final HTML output. The Concrete Screen and ConcreteHTMLScreen would then be the XSLT templates.

这篇关于MVC:两步和复合视图模式之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆