concept check on features, jobs and operations #19
-
I am architecting an app, using Lucid to reference some ideas. Unfortunately, I am stuck in a feedback loop and I am curious how others think this might fit into Lucid's concepts.
To accomplish that I have a SubmitOrderFeature. This feature upserts an order (UpsertOrderJob) and then runs a number of services for that order (UpsertOrderServicesOperation). So far, so good.
I abstract the request input on SubmitOrderFeature to accept a generic request whether it comes via the web or API. I then add SubmitOrderFeature to my API endpoint passing in the API request input. So far, so good.
In order to accommodate the upload I add a SubmitOrderUploadFeature. This feature needs to loop through each line and call the equivalent of SubmitOrderFeature on that line. Well, according to Lucid I shouldn't call SubmitOrderFeature from SubmitOrderUploadFeature. Okay, so I effectively take the contents of SubmitOrderFeature (a job and operation) and duplicate it inside SubmitOrderUploadFeature inside my loop. I don't love it, but I am only calling jobs and operations inside the new feature.
What I would like to do is have a SubmitOrderUploadLineFeature. But the result of this feature is effectively the same as what's called inside of SubmitOrderUploadFeature. So now, I have to duplicate code again from SubmitOrderUploadFeature because: a) I can't abstract into a Job or Operation because each line is calling UpsertOrderJob and UpsertOrderServicesOperation because they are both jobs The result seems to be a bunch of duplicated code fragments, which I would say is probably worse than having one feature call another feature or one job call another job. Thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@bdelamatre this is such an interesting case you ran into. I could think of an approache that i wish can help inspire you to come up with a solution to write the code once and reuse the parts that are needed. But before that, I would like to highlight that Lucid isn't here to incur constraints, you can do what you want with your code but the guidelines are there to help you keep it concise. All possibilities of PHP itself still exist so you may do whatever you like with the units you are writing. Use inheritance (OOP) Create a parent (abstract) feature Then you create So it goes as such:
Or you can extend
This approach works only when there's a high degree of similarity between the features that you're calling, which is the impression i got from your post. If this doesn't work please let us know here so we can explore the case further. |
Beta Was this translation helpful? Give feedback.
@bdelamatre this is such an interesting case you ran into. I could think of an approache that i wish can help inspire you to come up with a solution to write the code once and reuse the parts that are needed. But before that, I would like to highlight that Lucid isn't here to incur constraints, you can do what you want with your code but the guidelines are there to help you keep it concise. All possibilities of PHP itself still exist so you may do whatever you like with the units you are writing.
Use inheritance (OOP)
Create a parent (abstract) feature
SubmitOrderFeature
from which the rest of the features descend. In itshandle
method you runUpsertOrderJob
andUpsertOrderServicesOperation
…