mvc Primavera: Una vista de uno o dos pasos Paso View?

gstackoverflow:

Estoy leyendo el libro famoso de Fauler "patrones de aplicaciones empresariales" Y no puedo entender la diferencia semántica entre una vista de pasos (parte superior) y de dos etapas Vista (parte inferior)

introducir descripción de la imagen aquí

He leído todo el texto pero entendía una sola cosa: En caso de dos vista paso tengo 1 intermedio adicional lógico vista. Y esto es ejecutado por alguna "entidad" global.

Realmente no es claro para mí por qué lo necesito. En mi consulta utilizo la primavera - mvc para la aplicación web. Podría explicar qué patrón se utiliza dentro de este marco? Pudiera elegir / cambiar?

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.

Si usted no sabe por qué es necesario utilizar dos etapas del patrón de vista, probablemente, no lo hace. En mi expierence nunca he visto esto en práctica en cualquier proyecto en el que he trabajado.

¿Qué pasa si usamos una vista paso en vez

En este caso si hay que hacer cambios globales en nuestra apariencia de la aplicación, tenemos que cambiar todas las vistas que genera HTML para el usuario.

Conclusión

Recuerde que el libro está escrito hace aproximadamente 20 años, y hoy en día tenemos un montón de grandes tecnologías que no existían hace 20 años.

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=312735&siteId=1
Recomendado
Clasificación