I’m currently re-writing a quote system in PHP which is used by multiple sales advisor’s. Each advisor can quote somebody multiple times a day and I’m looking for a better way of managing quote data from a MySQL table.
What would you suggest is the best way to write the system? I’m thinking of going down the route where each quote inherits a kind of quote class which allows it to perform certain operations. I can’t see why this would be bad, since the idea of writing a class is for it to be used by multiple children?
If I did this though, the question then becomes, how do I keep a lookup of these quotes when they’re being displayed and ensure that the right quote performs the right action? Perhaps an array with a pointer to the class it comes from, or dynamic variable names?
I’m doing something similar with a client’s website I’m working on. They want to be able to offer promotions, of which could be something like buy one get one free, a set percentage off, a free item, etc. I made an base abstract Promotion class that handles some of the default functionality, but also defines other abstract methods —
load()andsave()being the important ones here I believe.When the information about a promotion is saved, it also stores its class name in there. When the system goes to load that row from the database, it sees the class name, creates an instance of it, and tells it to load the Promotion with information from that row.
Since each Promotion might have different ways to save or load, the table is essentially a template that could be used, but doesn’t prevent each individual Promotion subclass from creating its own.
You could essentially do the same thing with your Quotes. Store which subclass saved the quote, and have it load the information. Then when it comes time to display, you can call a general
$quote->toHtml()— or however you want to do it — and it will be in charge of formatting itself appropriately.