In simple terms, could you please tell me the difference between the "Two-Step View" and "Composite View" Layout Design Patterns?
相关问题
- how to define constructor for Python's new Nam
- Keeping track of variable instances
- Object.create() bug?
- How to dynamically load partial view Via jquery aj
- std::vector of objects / pointers / smart pointers
相关文章
- 接口B继承接口A,但是又不添加新的方法。这样有什么意义吗?
- Forward request from servlet to jsp
- superclass mismatch for class CommentsController (
- NameError: name 'self' is not defined, eve
- Implementation Strategies for Object Orientation
- Check if the Type of an Object is inherited from a
- When to use Interfaces in PHP
- Are default parameters bad practice in OOP?
I see "Composite View" as the design pattern that suggests that you design your views via composition, or combining smaller parts (sub-views) to create the whole - This lends itself to increased reusability and better maintainability.
The "Two-Step View", on the other hand, is more of a specific implementation of the Composite View Design Pattern, largely driven by the Zend Framework Layout. This implementation suggests that you define all of the content your sub-views first (step 1), then allow a
layout
to render the sub-views at the appropriate places in the rendered HTML (step 2).I am generally a fan of a layout pattern but find the idea of two-steps (and defining all your sub-views first) limiting. I tend to think of layouts more along the lines of how Smarty 3's Extends/Block functionality works:
http://www.smarty.net/docs/en/advanced.features.template.inheritance.tpl
Functionality like Smarty's doesn't have a fixed number of steps in its composition - i.e. layouts can extend layouts and sub-views can be composed of further sub-views, etc.
Hope that helps.
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).
In simplified Pseudo-Code:
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.
In simplified Pseudo-Code:
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.