mercredi 4 novembre 2015

MVC - Which design pattern to use to transform request payload frrom the Controller to the Model

I'm using the MVC approach.

So when I'm receiving an EntityFilterRequest from the body (payload) for PUT/POST verbs, I need to transform the EntityFilterRequest to an EntityFilterRequestModel using

EntityFilterRequestModel.of(EntityFilterRequest).

The of method performs:

So basically instead of having the traditionally MVC approach, I have a layer between the C and the M to perform the conversion between the *requests and the *requestModels classes.

  1. All the necessary casts (String to Integer, Short)
  2. Default values for empty fields from the request
  3. Performs some check existents entity ids.
  4. Build new fields that will be necessary for the model layer.

Is this already a design pattern? Is there a better approach?

The main idea is to remove all validations describes above from the Model using the classes EntityFilterRequestModel and reduce the unnecessary code on the M layer.

If you needs more details please add comments and I will try to be more clear.

Aucun commentaire:

Enregistrer un commentaire