I had to clean up code for an online college application. There’s nothing particularly wrong with it, but it was complicated. Different degree programs had different prequisites, fees, required documentation, and questions. On top of that, students coming from the military get different fees, and previous students pay no fees and skip steps.
Obviously all this logic can get pretty complex – and cause bugs. I’m wondering if there’s a design pattern or coding method that would help with organizing the logic. I’m using PHP, not that it matters.
The strategy pattern seems to have the most potential, but it seems to me I’d need strategies on top of strategies for this.
I imagine the field of “Business Logic” might cover this at least partially, but searches haven’t turned up indications of any elegant coding methods to use.
Stategy pattern, as you suggest, sounds like it might fit the bill well – but with a fair bit of complex logic you’ll want to put this in a domain model, and not the transaction script you’re probably using now.
Fowler’s book Patterns of Enterprise Application Architecture has good explanations of this whole area of thinking about your app (he suggests you start with that and work from there).
And as others have said, unit testing always helps!