I am writing an application in python. The part I am little confused about is providing a little structure to my code.
This is the basic requirement of my web application.
I have these different end points:
- GET /reports/daywise.
- GET /reports/bulk_report_between_date_range.
- GET /reports/breakdown_by_age.
For each of these endpoints, I have defined a controller (a class which handles the computation of result)
My current design is as follows:
I have a base class defined ReportBuilder
, and it has some setter methods like
- setDateRange()
- setKeys()
- setQuery()
- Execute()
Now for each controller, I inherit from the above base class and I override methods if required.
class ControllerDayWise(ReportBuilder):
#..........
class ControllerBulkReport(ReportBuilder):
#..........
class ControllerBreakdownByAge(ReportBuilder):
#..........
The problem with above design is that I have to use setter methods in some specific order like I have to call setQuery()
before setDates()
, as query will obviously have dates in it.
While this works, I know there has to be a better way to structure my application. So while searching about it, I found using interfaces in python zope.interface
.
The idea is that I will create an IReportBUilder
interface and the controllers will implement it. Only with this, all the attributes
and methods
have to be redefined in all the controllers.
Any suggestions on pros/cons of each method that I have considered above? How should I approach this?