Decorator or Layout ?

2 views
Skip to first unread message

Francois Wauquier

unread,
Jun 10, 2009, 9:22:34 AM6/10/09
to gwt-mvc
Hello

Here is a design discussion that concerns 0.3 version.

I wish to discuss here about the decorator pattern, and how gwt-mvc
could simplify a multi-View (View as gwt-mvc call it) page in a Single
Page Application created with gwt.

Some definitions before:
a Decorator http://en.wikipedia.org/wiki/Decorator_pattern is an
object that use other objects to render a bigger service. The
important point is the decorated class dont need to know how it is
decorated.
I think this patterns apply here because each view are rendered
independantly, but a decorator define the position/placement of each
view.

A Layout is a common word to name the structure of a page in a
website, but also in a magazine.
A template is a common word to name a layout that could be reused in
different contexts.
Please correct me if i am wrong (the effort of explanation face the
problem of translation because i am french).

I imagine different ways to do that thing

1 / The initial HTML file IS the layout.

A controller could place any view at any place, using some div
containers.

That is someway how the poc is currently done.

Each time a controller would like to place one or more view on the
dom, it call (in the renderView method)
RootPanel.get("myDivId").clear();
RootPanel.get("myDivId").add(myView);
myView.render();

one way to help this would be to provide some class like
class DomPlacer() {
private String containerId;
DomPlacer(String containerId){
this.containerId = conatinerId;
}

public void place(View view){
RootPanel.get(containerId).add(view);
}

public void clear(){
RootPanel.get(containerId).clear();
}
}


The DomPlacers would be shared throught different controllers by some
undefined way.
DomPlacer could also be called Handler isn't it?

Advantages:
Good seperation of concerns between controller, placer, position
(html), style(css)
a DomPlacer could easily be mocked.

Disadvantages:
Many Small objects.
The initial html file may not cover all case.
containerId misspelling errors will only be thrown at runtime.

2/ One Object is reponsible of the placing: a Layout.
public interface Layout {
/** Place the static parts of the page and a welcome message */
public void init();

/** Place a view */
public void place(View view);

/** Place a view in a specific way*/
public void place(View view, LayoutParams params);

}

What is LayoutParams?
exemple A: You use a DockPanel and you want to pass args like North,
South, ...
exemple B: You have a page that could be shown in fullScreen and you
want to pass that in args.
other examples ?

I dont know if LayoutParams could be just an interface or something
like a map of params.
How to type this params? enum ?

Advantages:
The positioning may be more flexible, because managed by code.
The initial 'loading' indicator could be managed by the layout.

Disadvantage :
Does a layout is testable?

3/ Combination of 1 and 2
Find a common interface that allows each user to choose the better
strategy.
public interface Decorator{
public void init();
public void place(View view);
}

Advantages :
No imposed choice.
Possibility to switch from one to another

Disadvantage :
Harder to understand and maintain

For those who read all this, thank you
I hope a deep debate around this concerns.

François 'wokier' wauquier

Francois Wauquier

unread,
Jul 24, 2009, 4:12:14 AM7/24/09
to gwt-mvc
ok
Let's start with a the simple one :
a DomPlacer interface and DivWrapperPlacer as a first implementation.
Will be on 0.3 version.
Reply all
Reply to author
Forward
0 new messages