This is an interview question. Interviewer wanted a scalable solution

Goal is to find value of shopping cart. Cart could have 3 different types of items(Physical,Digital,URL).

Only Physical Items have a shipping address.

Only Digital items have a redeemable code that is used in a merchant site.

Only URL items have a URL that gives access to some online resource.

I've suggested having an Item class with price property which is extended by classes PhysicalItem, DigitalItem, UrlItem. Objects of these classes added to list which is iterated over to find the total order amount. Interviewer wasn't impressed.

Is there any good design pattern/approach that is best applied here?

  • $\begingroup$ A scalable solution? Did he mention databases or a concrete technology used by the company? Sounds like he expected something a lot more practical instead of theoretical. $\endgroup$
    – plshelp
    Aug 15, 2020 at 16:16
  • $\begingroup$ Can you please emphasise the CS angle? (I would not be impressed if the base class didn't include a multiplicity and required 4711 instances where 4711, say, octets were commissioned. A USofA interviewer may expect taxes parametrisable.) $\endgroup$
    – greybeard
    Aug 16, 2020 at 1:47


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.