So actually this is just the Assembler pattern by Martin Fowler.
So for example we will have an interface that looks something like this:
Code:
public interface MyService {
ViewObject getSomething(Integer id);
}
We will have a ViewObject assembler interface like:
Code:
public interface ViewObjectAssembler {
ViewObject assemble(Object o);
}
Code:
public interface ViewObject {
}
Code:
public class MyCustomViewObject implements ViewObject {
}
The MyService interface implementation looks something like
Code:
public class MyServiceImpl implements MyService {
private ViewObjectAssembler assembler;
public ViewObject getSomething(Integer id) {
MyDomainObject do = ... retrieve the domain object;
return assembler.assemble(do);
}
}
and a custom assembler being set by Spring:
Code:
public class MyCustomAssembler implements ViewObjectAssembler {
// handle the conversion
}
and this class van for example be called by the controller like this:
Code:
MyCustomViewObject x = (MyCustomViewObject) myService.getSomething(new Integer(5));
The ViewObjectAssembler can then be set in the application context of Spring on a project based approach.
Comments are more then welcome