Algorithms or patterns for a linked question and answer cost calculator
- by kmc
I've been asked to build an online calculator in PHP (and the Laravel framework). It will take the answers to a series of questions to estimate the cost of a home extension.
For example, a couple of questions may be:
What is the lie of your property? Flat, slightly inclined, heavily inclined. (these suggestive values could have specific values in the underlying calculator like, 0 degrees, 5 degrees, 10 degrees.
What is your current flooring system? Wooden, or concrete?
These would then impact the results of other questions. Once the size of the extension has been input, the lie of the land will affect how much site works will cost, and how much rubbish collection will cost. The second question will impact the cost of the extensions flooring, as stumping and laying floorboards is a different cost to laying foundations and a concrete slab. It will also influence what heating and cooling systems are available in the calculator.
So it's VERY interlinked. The answer to any question can influence the options of other questions, and the end result.
I'm having trouble figuring out an approach to this that will allow new options and questions to be plugged in at a later stage without having things too coupled. The Observer pattern, or Laravel's events may be handy, but currently the sheer breadth of the calculator has me struggling to gather my thoughts and see a sensible implementation.
Are there any patterns or OO approaches that may help? Thanks!