Spring MVCの:一歩ビューまたは二つのステップを表示?

gstackoverflow:

私は有名なFaulerの著書「エンタープライズアプリケーションのパターン」を読んでいると私は間の意味の違いを理解することはできませんワンステップビュー(上部)をし、二つのステップを表示(下部)

ここでは、画像の説明を入力します。

私はすべてのテキストを読んで、私はただ一つのことだけを理解:2つのステップ・ビューの場合、私は1つの追加の中間持っている論理的なビューを。これは、いくつかの世界的な「実体」によって実行されます。

私はそれが必要なのですか、なぜそれは本当に私のために明確ではありません。WebアプリケーションのMVC - 私の練習では、私は、スプリングを使用しています。あなたは、このフレームワーク内で使用されているパターンを説明してもらえますか?私は選ぶことができる/それを変更?

Aleksandr Semyannikov :

Stages responsibility

  1. The first stage translates a model to a logical view - you may think about it as a model described in terms of some universal form (Fowler uses XML for this purpose).

  2. The second stage is able to read logical view and is responsible for rendering this to rich interface with styles, formatting, and all stuff we love.

The way we get a view

You need to make some HTML having an object of next class:

public class Customer {
    private String name; //value: John Snow
    private String address; //Winterfell
}

On the first stage you translate that customer data into logical view:

<screen>
<title>Customer data</title>
<name>John Snow</name>
<address>Winterfell</address>
</screen>

XML is a good form to be transformed by XSLT, so our second stage is presented by some XSLT that transform our XML to some HTML code and surround it by footer, header, some menu items, etc.

Now we have a scheme: model -> fist stage -> xml -> second stage(XSLT) -> html -> user

What we can do with this

That scheme will let you:

  1. To create some themes for your application. In this example you can use XSLT script as a theme. You change the theme, your application appearance changes as well.
  2. To make some global changes in your application appearance by changing only one XSLT script.

If you use one-step view, you will have to change every view this case.

It's how Fowler describe this. You might find this interesting because in your edition of the book it might be described in a different way:

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. This way you can make a global change by altering the second stage, or you can support multiple output looks and feels with one second stage each.

How it is related to Spring MVC

Spring MVC implements another pattern - model-view-controller. Our pattern is a view part and we are free to decide what exactltly view technology to use with Spring MVC. If you will find some view framework that implements this pattern, you are free to plug it to Spring MVC.

あなたは二段ビューパターンを使用する必要がある理由がわからない場合は、おそらく、あなたはしないでください。私expierenceでは、私は、これは私が働いてきたすべてのプロジェクトで実装見たことがありません。

私たちは、代わりに一歩ビューを使用している場合

我々は我々のアプリケーションの外観のグローバル変更を加える必要がある場合は、このケースでは、我々はユーザーのためのHTMLを生成し、すべてのビューを変更する必要があります。

結論

本は20年ほど前に書かれていることを忘れないでください、そして、今日、私たちは20年前には存在しなかった偉大な技術の多くを持っています。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=312732&siteId=1