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?