Thursday, August 7, 2008

Naked Objects in WPF?

There is a rather niche architectural pattern called naked objects. In this pattern, you build your entire application as an abstract domain model. If you do MVC, this is like building the application using only the M. Your users will then interact with this model directly.

I call this a niche pattern because none of the major frameworks support it. What I want to explore though is how we can fake it in WPF.

If you use strict naked objects, you won't build a user interface. The framework will take care of it for you. Frankly, this kind of scares me. I only imagine the monstrous forms that will come out of this thing.

In WPF, you can define a template for arbitrary classes. What I'd like to try is to define a UI form by dropping domain objects and importing a resource that will act like a skin. That resource will have the templates that define how the properties of my objects will map to UI controls.

This is just a thought I've been kicking around though. One problem I haven't worked out is how to map events on the controls to method calls on my objects without making every single method a routed event handler. I'll have to see if there is a generically capture the events on some controller class and automatically re-map them to method calls.

Why would I want to do this? Well... I've got a couple 2000 line code-behind file's I've inherited that prove, yet again, that you can write spaghetti FORTRAN in any language.

No comments: