This is a template template, so I will illustrate it with a simple example of an address book application.
Firstly, a few assumptions. 1. It seems acceptable to directly use database domain objects as backup storage for Spring MVC forms.
Iteration 1 of my application I created a JPA object object mapped to various attributes. Using the DAO pattern, I created a persistence object that can getAll to store and delete people from the database. Also, I have a factory method, create so that I can get the person object. Using this DAO object, I am creating a simple web interface. All is well.
In iteration 2, I need to support several types of repositories, so I am creating an interface for a person who has several implementations, and an interface for saving DAO, again with several implementations. In addition, the person has been expanded to have multiple addresses.
interface IPerson { public String getName(); public List<IAddress> getAddresses(); }
But when it comes to updating the web interface to be able to deal with these multiple implementations, I have a problem. The persistence implementation is introduced by Spring. And since this persistence object has a factory method, I am well versed in the implementation of IPerson. But, if I want to do something unusual, for example, to allow the transfer of multiple addresses as part of a single request, then I have a problem. To let this work with Spring, you seem to need to use an AutoPopulatingList, so Spring can just .get (#) write a copy of the attributes.
Thus, one of the solutions to this work is the requirement that all persistence implementations use an autopopulation list and create the correct implementation for all child classes. This is appropriate given that we will need to apply this @PostLoad with JPA, as the base lists will be replaced with Hibernate.
An alternative is the absence of any implementation assumptions passed into the persistence implementation, and the conversion / copying of objects to the appropriate type. This looks better, because then the Domain object remains simple, and all the storage complexity is in the DAO. In this case, we will use the default implementation * of the IPerson and IAddress interfaces.
Despite the fact that I like the second option better, I'm not necessarily comfortable with this situation. Can anyone offer any ideas or tips?