Is Structure Layout View a code smell?

I have an application that was built by using a double layered architecture. I needed to have a model where I store essential data about actions in this system.

This system must be able to display these actions on screen and needs to be in a Composite type fashion(an action can contain sub-actions, but also can contain other components like buttons, labels, etc.).

The structure model holds data and structure about actions(but not their positioning). The layout model is an observer of the logic model and holds the position and z-order of all components(actions + buttons + labels + etc.). And lastly there is the View that is an observer of the logic model and of the layout model to be able to display all the components(actions, buttons, etc.).

By doing this I've separated an action into three components(structure+layout+view). This separation was necessary because I wanted to have a layer where I make the decision of which component is under the cursor separated from the layer where I make structural decisions(like adding/deleting actions) and separated from the layer where I display all components. Now I have three layers that combined form one unique component.

The problem with this is that a component becomes formed from three distinct layers and it is a little harder to mantain.

Please tell me if there could be a better design for this problem.

Thanks in advance

[1430 byte] By [oopcodera] at [2007-10-2 11:00:55]
# 1

Take a look at the TemplateView or TwoStepView design patterns. You should be able to separate a view template from its sub-components. All are properly View classes; however, the templating classes should not depend on child sub-components (the template should not really 'care' about what is being displayed according to its layout). However, the template classes may offer call-back methods for child components to call (for example, close window or access frame-level menu).

- Saish

Saisha at 2007-7-13 3:31:18 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

Thank you for your reply.

I have found some documentation about TemplateView and TwoStepView at http://patternshare.org/default.aspx/Home.MF.

TwoStepView but it seems to apply to web applications. My application is a desktop application written in java and I don't know if these patterns can be applied there. I appreciate very much if you could give me some advice.

oopcodera at 2007-7-13 3:31:18 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
By the way, could you give me some links where I could find some informations about how to implement those patterns?Thank you again for trying to help me,oopcoder.
oopcodera at 2007-7-13 3:31:18 > top of Java-index,Other Topics,Patterns & OO Design...
# 4

The following applies mainly to PHP and web pages, but the principles are the same: http://www.phpwact.org/pattern/template_view.

You want a series of template-generating classes. One option in doing so would be an event model:

interface TemplateComponent {

abstract public void render(final JComponent parent);

}

class TemplateManager {

private TemplateComponent header;

private TemplateComponent body;

private TemplateComponent footer;

public TemplateManager(TemplateComponent header, TemplateComponent body, TemplateComponent footer) {

super();

this.header = header;

this.body = body;

this.footer = footer;

}

public void render() {

JComponent panelHeader;

JComponent panelBody;

JComponent panelFooter;

// Create a series of JComponent and add to your layout

// This will be the template layout

header.render(headerPanel);

body.render(bodyPanel);

footer.render(footerPanel);

}

}

- Saish

Saisha at 2007-7-13 3:31:18 > top of Java-index,Other Topics,Patterns & OO Design...