views:

118

answers:

1

I am building an application that will send an API call and save the resulting information after processing the information in a APIRecord(models.Model) class.

1) Should I build a separate class in such a way that the class does the API call, processes the information (including checking against business rules) and then creates an instance of my APIRecord() class?

Or

2) Should I build a separate class with the appropriate methods for processing, and calling the API, and then in my model, override the APIRecord.save() method to call the separate class's API methods and then save the results?

Or

3) Should I build my model class with the appropriate methods for calling the API and processing the response (including checking for certain values and other business rules)?

I tried # 2 and ran into problems with flexibility (but am still open to suggestion). I'm leaning towards # 1, but I'm not sure of all the negatives yet?

+1  A: 

it is design decision. it depends to your design and programming interests. i used the combination of three methods you said. if i need to some informations that can be build from other fields then i will create an internal function in model class. if i need other records of database to do something i will create an function outside of model class. and other unusual needs will be computed everywhere i need them.

chezgi