I've got a mature (heh, am I mature?) system that's continually getting new feature requests --- I'm suffering from "feeping creaturism", I guess. Here's an issue that's pretty hard to wrap my head around: whether I could have designed it from the Beginning (3 years ago now) with a better way to handle the situation below. I'd really like to see if I can learn something from this.
Please forgive the $cats abstraction; this is an object-oriented system that we rely on constantly at work.
I've a herd of $cats; each produces a litter of $kittens and puts them in the $nursery and then dies. The $nursery staff looks them over and decides what breed they are, what color their fur is, and so on. The $kittens are tagged with these qualities by the $nursery and then sends them to $PetsMart for sale. When all the $kittens are sent to $PetsMart, the $nursery goes out of business.
This has been working well enough as designed; all the data we needed to know about kittens 3 years ago has been programmed into the system.
However, the CEO at $PetsMart now wants to know which $kittens were conceived under a full moon, so he can tag them as such and get a higher price. 3 years ago we had no idea he was interested in such things.
Although the $cats know when their kittens are conceived, $PetsMart doesn't have a way to talk to dead cats.
The nursery could ask the $cats about this, but it wasn't written to do so.
In other words, the objects are discrete; a new flag ($born_under_fullmoon) can't be set at birth and retained until sale unless we alter the affected parts of the system. The first object can tell us that a certain flag should be set, but no mechanism exists to transmit the new data through the entire system.
Now, I've analyzed three possible "fixes":
I can add a boolean field to the $nursery DB queue and the $cats can set this their conception dates. The possible problem is that modifying the database means I'll have to review the entire system (since the "nursery" touches both the $cats and the $PetsMart) to make sure that other DB calls don't break.
The system has a config file, so I could create an array of $cats that are known to have conceived their litters during a full moon there. But then the config file must be altered for any new $cat that gets romantic at that time of the month. Plus, the $PetsMart object must read the config file and probably import it into its methods with "global $config". That feels dirty (is it?).
A 3rd alternative, possibly the best, is to create a new table that $cats can write to and $PetsMart can read.
I'll probably pick option #3. What I'd like to know, if you can even follow my story ... is there anything I might've done 3 years ago to foresee this and make my objects able to communicate with any part of the system, even though they don't exist any longer?
Is this, for example, a place where an object-oriented database might have helped? A particular pattern I didn't use?
Thanks for your help 🙂