mardi 23 décembre 2014

DAO design principle

What is the better design for a DAO in Java with the below use case,



Class Dummy{
String someText;
String spanType; (Day/Week/Month)
}


Based on the spanType value the dummy object is stored in either Dummy_Day or Dummy_Week or Dummy_Month table.


OPTION:1



//Here the Dao dynamically determined the table based on the value of each Dummy object
void saveDummys( List<Dummy> dummies );


OPTION:2



//Here the table to be stored is designed into the API signature
void saveDayDummys( List<Dummy> dummies );
void saveWeekDummys( List<Dummy> dummies );
void saveMonthDummys( List<Dummy> dummies );


The argument against Option:1 i hear is the business class that invokes the Dao should know where the data is being saved as opposed to leaving it all to the DAO.


I feel that the business class needn't care where or how the data is stored as long as the DAO does it consistently no matter what the implementation is. But Im not really opposed to the rationale that the business class should know which table has the data as this makes the code readable and error hard to hide.


Aucun commentaire:

Enregistrer un commentaire