Hi!
I only noticed now that according to the RFC, DTOs cannot contain methods. I
can understand why this is so, and I do not object.
However, I have found a very practical design pattern whereby I use classes
that act both as DTOs and domain value objects. In effect, this means that they
are DTOs with methods. I am willing to pay the price of having “bloated” DTOs
for this convenience.
Would there be any way to allow configuration to permit this?
If that is out of the question then any suggestions as to what I could do so as
to not have to have “duplicate” classes (DTOs and domain VOs)?
Example:
Domain object API
public interface SomeObject {
String foo();
String bar();
String calculateFoobar();
}
Implementation
public class SomeObjectDTO extends DTO implements SomeObject {
public String foo;
public String bar;
public SomeObjectDTO() {}
public SomeObjectDTO( String aFoo, String aBar ) {
foo = aFoo; bar = aBar;
}
@Override public String foo() { return foo; }
@Override public String bar() { return bar; }
@Override public String calculateFoobar() { return foo + “:” + bar; }
}
I like the above because:
* No duplication
* As a DTO, can be sent over the wire and serialised
* Implements the domain API
Cheers,
=David