On Nov 26, 2008, at 9:05 PM, Adrian Crum wrote:

I would like to work on cleaning up the screen widget Java code. Here are some of my ideas:

1. The screen widget model classes are trying to be too many things. As a result, they contain some messy and scary code. I'd like to see the model widget become more of a data structure, and move the rendering code into the rendering classes.

Do you have any specific bits of messy code in mind? I don't mean to imply that I don't believe this might help, but how does moving the code from one class to another clean up the code?

2. Use a true visitor pattern in the model widgets. The current pattern is what I would call "befuddled double dispatch with baggage." Methods like

public void renderWidgetString(Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer)

would become

public void accept(ScreenWidgetVisitor visitor).

Rendering classes would implement the ScreenWidgetVisitor interface. The model widgets won't need to be concerned with writers, contexts, or any other messy details.

Sorry if I'm a luddite, but this seems to make the code more difficult and makes me think things like: what does "accept" mean, and what would a method named that actually do? what is actually being passed into this method... maybe that can help me understand it... oh... what's a "visitor"?

I guess what I'm saying is that just because someone writes up a practice and calls it a best practice or a "pattern" doesn't mean it's always a good idea.

3. Convert the existing artifact gathering code to a screen widget visitor. That would get the artifact gathering code out of the model widgets and put it where it belongs. It would probably simplify the artifact gathering code as well.

I'm not sure what this means... but I might be missing something obvious. Hopefully someone else has more helpful comments.

-David

Reply via email to