We have a GWT + GAE app and here is the situation:
We have two different forms/pages:
- Register as a Blood Donor
- Register as a Eye Donor
Till now we had underlying two different entry point classes which calls two different services one implemented as RegisterBloodDonorServiceImpl and another as RegisterEyeDonorServiceImpl.
Now, we want to implement a feature where we want to give option to the blood donor to register as eye donor as well. As the data is almost same so we dont want the end user to fill two forms and instead just provide a checkbox to achieve the same on the blood donor form.
So, now the question is how should we implement it?
-
Should we call the RegisterEyeDonorServiceImpl from inside the RegisterBloodDonorServiceImpl after blood donor data is persisted in the service? If yes then we are not sure how to call one service from another service?
-
Should we invoke two services one after another in the entrypoint implementing class?
-
Any better idea ?
Where we’ve had code in our project that needs to be called from more than one service, we’ve found it best to extract the code from our
*ServiceImplclasses and into its own class. Then each service can hold its own instance of this class as required.So in your case, I would recommend creating a class with a name such as
EyeDonorServiceCallswith a method likeregisterEyeDonor.RegisterEyeDonorServiceImplwill keep an instance of this class and callregisterEyeDonorwhen it receives an appropriate service call.RegisterBloodDonorServiceImplwill keep another instance and callregisterEyeDonoras part of the registration for blood donors if the appropriate check box has been ticked.