IBM Interview Question
Software Engineer / DevelopersCan't this be done using a simple function? Maintain a single global hash having location=>shipping cost. Cache this hashtable for good access speed. Now, have the web interface pass the baseprice + location to this function. This function accesses the hash, calculated the total price & done.
What could be wrong in this approach? Isn't having Singleton Class an overload? The class has to check each time if an instance of the class already exists etc. When there are millions of transactions will this not harm the speed?
Have a single class and create a singleton instance. The single instance will serve millions of transaction. It will calculate shipping based on the customer location. Customer location needs to be passed as input to the instance method.
- Raj August 18, 2010