java - Decoupling backing store with Spring Web MVC -


This is a design pattern question, so let me explain it as a simple example of the Address Book app.

First of all, some assumptions 1. It seems to be acceptable to use DB domain objects as a backing store for spring MVC forms.

Changes in your app 1 made me JPA-mapped person object with different attributes. Using the DAO pattern I have created a firm object that can get, store and remove all the databases from people. Besides, I have a factory law, make it, so I can get the object of a person. Using this DAO object I make a simple web front end, all are good.

In Walking 2 I need to support many storage types, so I create an interface for the person, which has many implementations, and an interface for the DAO firmness, again with several implementations . In addition, the person was extended to receive multiple addresses.

  Interface eyeshadow {public string getName (); Public listing & lt; IAddress & gt; GetAddresses (); }  

However, I have a problem to update the web interface to be able to deal with these multiple implementations. I have inclined through stubborn processing spring. And, because it is a factory system with firmness. I have all the good for implementation of Ipson. But, if I want to fancy something like allowing multiple addresses to be presented as part of a request, then I have a problem To allow you to work with spring, you need to use an autopululing list, so it can be just spring. (#) Make a copy of the record.

Therefore, it is a solution to work, use all the perseverance implementation to use an autopopulating list, and all child classes require the right implementation, is it appropriate that we give this to @PostLoad It is necessary to apply with JPA because the base lists are replaced by hibernate.

There is no impression about the implementation of the option interest, and not to convert the objects into the appropriate type. It sounds good, as the domain object is kept simple, and all the storage Complexity occurs in DAO In this case we will use the default * implementation of the iPerson and IADRS interfaces.

Although I like the other option, but I am not necessarily comfortable with this situation. Anyone can provide insight or advice?

Do not make any assumptions about the option. Implementation persistence was passed in implementation and the object To be changed in the proper way. It feels good, as the domain object is kept simple, and all the storage complexity is in the DAO. There is no impression about implementing the option alternatives and copy / copy the objects in the proper manner.

This is a package of domain MVC

  • domain objects by which there is no reference to the services / DAO code (seems
  • To handle form controllers, use "command" or "use a different layer of form" objects that control that data Let's model the user who is filling in the form, not your domain The Gadgets user submits the controller that binds the request for the "command" / "form" object, and your controller converts the map or these beans into your domain bean. For example, a very rich User object, but when new users sign up, they only have to supply 2 or 3 fields, and I will call it as UserSignupCommand and UserSignupController I use it because it uses the command class ( user is not an domain object). The controller is then responsible for taking the UserSignupCommand Bean and either the data Converts user into beans or whatever other type of input your layer of services is required.

    I do not recommend using domain objects as form backing objects because in most cases the correct match between "I am modeling the object in my domain" and "data provided by the user" is not.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -