Adding, deleting, and modifying an object's workflow without making code changes

Status
Not open for further replies.

hanser

Ars Legatus Legionis
43,847
Subscriptor++
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:
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)
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?
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
Maybe it's not possible without making code changes. And maybe that's OK.

Maybe a more realistic is simple polymorphism with an abstract ProductType parent. Each child class would implement its own version of a doOperations() method, with an IEnumerable or IDictionary as its argument. This might be more expedient than building the mother of all data-driven, super generic data processing abstraction.

Just thinking out loud.
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
Upon further thought, trying to pass the operational knowledge into the cache request handler is wrong. It should live within the ProductType subclass. It's probably not possible to have this knowledge be codified in a data store. I had hoped that it would be possible to add and subtract ProductTypes without changing code, but I don't think that's going to be possible.
 

btmlltt

Ars Legatus Legionis
15,156
Without the domain of actions being either limited enough that you can merely implement them all generically and store operation types or the domain being restricted enough that you can write a domain-specific language that is stored in your datastore, then I think the way to go is to subclass each new type and design to have the easiest/least amount of code changes to add a new type.
 

LordFrith

Ars Legatus Legionis
25,252
Subscriptor++
We have this same problem. We have developed a system of keeping state descriptions that are easily modified to describe the workflow. The individual steps contain a "do this to this thing."

It's much more of a "You are ready to proceed with this case" type of system, where each then runs and updates the next in the workflow. So, the object itself doesn't know anything about its workflow.

Also, expect code maintenance. You will come to imagine that the production line is reading your code and coming up with cases that break your assumptions.
 

Ardax

Ars Legatus Legionis
19,794
Subscriptor
It's probably not possible to have this knowledge be codified in a data store. I had hoped that it would be possible to add and subtract ProductTypes without changing code, but I don't think that's going to be possible.
It may be possible for some classes of productType (and there's no harm in taking care of those when reasonable), but ultimately...

You will come to imagine that the production line is reading your code and coming up with cases that break your assumptions.
...you'll feel this.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
Trying to have no code is IMO a bad idea in most cases because there will never be enough time (or even feasibility) to get the domain modeled well enough that the schema used (be it database, xml, JSON etc.) can encompass everything you have, or get in future without someone jamming something into the wrong hole because there was no where else. At that stage you no longer have the clean data you were striving for and get hacks rampantly hitting all the other layers in the system.

Use code, you want a new product type, write the code (reusing things as you can, via composition if at all possible). Doing things in code is often easy.
 

LordFrith

Ars Legatus Legionis
25,252
Subscriptor++
[url=http:/civis/viewtopic.php?p=27534965#p27534965:199vyjie said:
ShuggyCoUk[/url]":199vyjie]Trying to have no code is IMO a bad idea in most cases because there will never be enough time (or even feasibility) to get the domain modeled well enough that the schema used (be it database, xml, JSON etc.) can encompass everything you have, or get in future without someone jamming something into the wrong hole because there was no where else. At that stage you no longer have the clean data you were striving for and get hacks rampantly hitting all the other layers in the system.

Use code, you want a new product type, write the code (reusing things as you can, via composition if at all possible). Doing things in code is often easy.

Also, don't build a framework for this until you have at the very least, 3 examples of it being done in as varied a way as are likely to happen.

Too many people build frameworks off of a single example, because frameworks are fun, and then fail miserably when the second example is completely different.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
[url=http:/civis/viewtopic.php?p=27535189#p27535189:ckopxler said:
LordFrith[/url]":ckopxler]
[url=http:/civis/viewtopic.php?p=27534965#p27534965:ckopxler said:
ShuggyCoUk[/url]":ckopxler]Trying to have no code is IMO a bad idea in most cases because there will never be enough time (or even feasibility) to get the domain modeled well enough that the schema used (be it database, xml, JSON etc.) can encompass everything you have, or get in future without someone jamming something into the wrong hole because there was no where else. At that stage you no longer have the clean data you were striving for and get hacks rampantly hitting all the other layers in the system.

Use code, you want a new product type, write the code (reusing things as you can, via composition if at all possible). Doing things in code is often easy.

Also, don't build a framework for this until you have at the very least, 3 examples of it being done in as varied a way as are likely to happen.

Too many people build frameworks off of a single example, because frameworks are fun, and then fail miserably when the second example is completely different.

++
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
[url=http:/civis/viewtopic.php?p=27534033#p27534033:204h3im6 said:
LordFrith[/url]":204h3im6]It's much more of a "You are ready to proceed with this case" type of system, where each then runs and updates the next in the workflow. So, the object itself doesn't know anything about its workflow.
This is actually a problem for us, and I've had several conversations about this with the head of mfg architecture. We have this notion of "ready to produce" that's different for each product type. This "ready to produce" state is a trigger for a scheduling component to come in and schedule it for production. Unfortunately, this "ready to produce" state is specifically set by various components during the "ingest order and do stuff" process, which is bigger than just my service.

IOW, this product-specific knowledge is spread across subsystems, which feels wrong. In reality, I feel like each product type should have various characteristics that are specific to that product type. In the case of embroidery, for example, when the computation is complete, and the artifacts are cached, there'd be two statuses: "computation complete" and "artifacts cached".

The scheduling component would then know that it's ready to be made--probably by querying the ProductType to understand what, specifically, "ready to produce" means[1]. I.e. infer that it's ready rather than having a boolean somewhere that gets explicitly twiddled by some random component that doesn't have any understanding of product types or know what the boolean it's changing means.


[1] In reality it would just cache the "ready to produce" semantics when it starts up after each release.
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
[url=http:/civis/viewtopic.php?p=27534965#p27534965:1dnl0k9z said:
ShuggyCoUk[/url]":1dnl0k9z]Trying to have no code is IMO a bad idea in most cases because there will never be enough time (or even feasibility) to get the domain modeled well enough that the schema used (be it database, xml, JSON etc.) can encompass everything you have, or get in future without someone jamming something into the wrong hole because there was no where else. At that stage you no longer have the clean data you were striving for and get hacks rampantly hitting all the other layers in the system.
Yeah, that's where we are today. I'd prefer to avoid kicking the can further down the road if I can. I also don't think that there's enough value to be captured by coming up with a data model or DSL that's rich (and correct) enough to warrant attempting.

[url=http:/civis/viewtopic.php?p=27535189#p27535189:1dnl0k9z said:
LordFrith[/url]":1dnl0k9z]Also, don't build a framework for this until you have at the very least, 3 examples of it being done in as varied a way as are likely to happen.

Too many people build frameworks off of a single example, because frameworks are fun, and then fail miserably when the second example is completely different.
Earlier this morning I reached out to some people so I can get a second and third use case. I am 100% certain there are details I haven't considered, because I don't know what I don't know.
 
Status
Not open for further replies.