I have a problem, and I suspect the general case of this problem has a name. But I don't know what it is.
I develop software used in manufacturing custom objects. I developed a service that caches the various artifacts required to produce whatever the object is, and it works for one product type, which was all that was required for v1 which had a very tight schedule. vN, though, will need to work for all product types, so I need to generalize the service. Those objects are myriad: printed objects, embroidered objects, engraved objects, and so forth. Each has their own production workflow.
Some workflows require additional operations before the object can be made. For example, in the case of an embroidered item, we have to compute a value and store it in the database. This value is essential to efficiently scheduling production of embroidered items. This is done as part of the caching process, because 1) it has to happen as soon as the order enters the plant, and 2) I already have the artifact used in the computation in memory. Easy-peasy.
Generalizing this problem (must do something product-specific during caching) is not easy because we have dozens of product types. In a perfect world I would like those steps to be enumerated by reading data so no code has to change. Ideally there would be a call to get the required operations, and those operations (if any) would be applied to the relevant bits of data during the cache request lifecycle.
I'm thinking something like this:
Trouble is, I have NO idea what the requiredOperations data structure would look like--or if it's even possible to create one that represents my problem, because operations could be anything:
- Computations
- CRUD operations on a filesystem or in a database
- Pinging another service
- Etc.
In my perfect world, adding another ProductType wouldn't require code changes.
Questions:
1) Does the general case of this problem have a name?
2) How would you approach this problem?
I develop software used in manufacturing custom objects. I developed a service that caches the various artifacts required to produce whatever the object is, and it works for one product type, which was all that was required for v1 which had a very tight schedule. vN, though, will need to work for all product types, so I need to generalize the service. Those objects are myriad: printed objects, embroidered objects, engraved objects, and so forth. Each has their own production workflow.
Some workflows require additional operations before the object can be made. For example, in the case of an embroidered item, we have to compute a value and store it in the database. This value is essential to efficiently scheduling production of embroidered items. This is done as part of the caching process, because 1) it has to happen as soon as the order enters the plant, and 2) I already have the artifact used in the computation in memory. Easy-peasy.
Generalizing this problem (must do something product-specific during caching) is not easy because we have dozens of product types. In a perfect world I would like those steps to be enumerated by reading data so no code has to change. Ideally there would be a call to get the required operations, and those operations (if any) would be applied to the relevant bits of data during the cache request lifecycle.
I'm thinking something like this:
Code:
foreach item in request queue
productType = getProductType(item)
requiredDownloads = productType.getRequiredDownloads() //XML files, images, JSON, whatever.
foreach download in requiredDownloads
downloadedContents.Add(path, contentsOfDownload)
requiredOperations = productType.getRequiredOperations()
doOperations(downloadedContents, requiredOperations)
foreach artifact in downloadedContents
writeArtifact(artifact)
- Computations
- CRUD operations on a filesystem or in a database
- Pinging another service
- Etc.
In my perfect world, adding another ProductType wouldn't require code changes.
Questions:
1) Does the general case of this problem have a name?
2) How would you approach this problem?