I’m designing a shipping application and trying to use Clean Architecture. I’m trying to figure out where to hold state of a Shipment object so that I don’t have to re-instantiate a new object every time a user clicks on a button in the UI. Here is the flow.
- User enters a delivery number in the UI
- UI Controller handles the UI event and instantiates an instance of the Use Case Interactor a. A repository instance in passed into the constructor of the Use Case Interactor
- The Use Case interactor instantiates an instance of Shipment by calling a Factory(e.g. CREATE_BY_DELIVERY). The factory calls the Repository to collect the data from the database.
- Delivery data is populated on the UI
- User then clicks a Rate Quote button
- UI Controller handles the button click event and calls the RATE_QUOTE method of the Use Case Interactor a. Does the Use Case Interactor need to call the Shipment factory again as in step #3 or can the Use Case Interactor get an instance of the Shipment object that was already created in step #3?
- Rates are displayed on the UI
- User then clicks the PROCESS shipment button
- UI Controller handles the button click event and calls the PROCESS_SHIPMENT method of the Use Case Interactor a. Does the Use Case Interactor need to call the Shipment factory again as in step #3 or can the Use Case Interactor get an instance of the Shipment object that was already created in step #3?
Should the state of the shipment object be an instance variable on the UI Controller, Use Case Interactor or the Repository? Ideally, I'd like to save it somewhere so I don't need to keep creating a new object every time a user clicks a button on the UI.
Thank you in advance!