The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Rishi (1) [Avatar] Offline
#1
I am using the exposed domain model pattern. In order to prevent the presentation tier to perform updates without going via a domain service I am writing the presentation tier using read only interfaces of the domain objects. This strategy is suggested in your book on page 293 while using the domain model pattern.



I am using Hibernate for the persistence tier along with Spring in the business tier. I am using Springs OpenSessionInViewFilter to keep hibernate sessions open until rendering of the page is complete.



But I am confused as to how an update would be performed if only a read only interface is returned to the presentation tier.

e.g

Suppose I have the Domain object interface Person and its concrete implemetation PersonImpl, and a Service class as follows:



interface Person {

getName();

}



class PersonImpl implements Person {

private String name;

public getName() {
return this.name;
}

public setName(String person) {
this.person = person;
}


}



class PersonService {

Person readPerson (String name) {
...
}

void updatePerson(PersonImpl person) {
...
}



My question is this - When the presentation tier acquires a Person Object, how will it's fields be updated, since Person does not have any mutator methods ?

Also the domain service method updatePerson expects a parameter of type PersonImpl, but all the presentation tier has is a Person.



I could not find a solution to this problem in your book or in the sample code.

Thank you in advance.

-Rishi
ceracm (110) [Avatar] Offline
#2
Re: Performing Update while using Read-only views of Domain Objects
Rishi,

I didn't explicitly discuss the issue of the presentation tier updating the domain objects directly and so the book focusses on readonly views.

The interface should specify the methods that the presentation tier needs to call.
If it needs to update the domain object then the interface should define methods to do that.

Also, if the service expects a PersonImpl then you need to pass the PersonImpl or downcast. There is no way around that. You could change the service to take a Person and downcast internally. Alternatively, the controller part of the presentation tier to use PersonImpl but would the View part to be written in terms of Person.


Chris