0

Im writing a web-service that has couple of APIs to get data from a data store. The high level view would look like this

     getBlahForDate()
         ---->             ----> 
Client           Service            Data store ( Stores Blah )
         <----             <----
        List<Blah>

While thinking about how to design the code within the service, im stuck at choosing the right design pattern

I have the following layers

1. serviceLayer ( one class for each API, does validation on input )
2. daoLayer ( fetch data from dataStore )
3. modelLayer ( pojo defining domain objects like Blah )

The only "work" done by the service is validating the input and reading from data store and converting domain model to transport model before sending the response. I could have the service layer directly use the dao and send the response. But I would like to know which design pattern would fit the use case. Also this to me looks like an Anemic domain where the domain object is just a pojo with no business logic. But then there is no business logic other than validating if the data from the store is valid for the fields in the model. Appreciate if you can tell me what the accepted/common way to handle this case.

broun
  • 2,483
  • 5
  • 40
  • 55

1 Answers1

0

I would do:

  • Your HTTP service layer will do: HTTP body, routing validations, call the right GenericManager given the URL...

  • a GenericManager for example (with get, post, put, delete, list methods) returning Model or a List of Models. A manager can call other managers The developer will only define the action wanted: get or post... or even all the methods. I think that it is good to process Business rules validation at this level. I think that Business rules validation should be a layer in the application. Because you may want to share the the Business rules validation.

  • an AbstractDao for example (with get, post, put, delete, list methods) returning Dao Model or a List of Dao Models. (the Model Dao and the Model render to client can/may be different)