Polymorphic Orderer

Geoffrey Challen // 2021.9.0

Create a method named order. order should accept a single parameter, a Restaurant? to order from, and return a String, a comment on your order. Depending on which subclass of Restaurant it is, you should respond differently:

  • If the restaurant is an Fancy restaurant with name "MIGA" you should order "At MIGA I'll order something inexpensive"
  • If the restaurant is an FastFood restaurant with name "Chipotle" you should order "At Chipotle I'll order something healthy"
  • If the restaurant is an Vegan restaurant, then they will have a String property cuisine. If their cuisine is "Thai" and name is "Vegan Delight" you should order "At Vegan Delight I'll order delicious Thai food".

All Restaurants have a name that you can retrieve as the property name. If the restaurant is null or not one of the kinds described above, return null. Do not solve this problem using method overloading.

Note that we are not implying that there are not fancy vegan restaurants or fancy fast food restaurants or vegan fast-food restaurants. If anything, the ability of real entities to resist strict classification is one of the limitations of Kotlin's object model.