Imagine you have a menu with dishes each dish should be available in multiple languages (French , English , Arabic , ...). The Dish
class contains a list with Language
type objects.
class Dish {
List<Language> languages
void addLanguage(Language lg){...}
}
class Language { getDescription(){}}
class French extends Language{}
class Menu {List<Dish> dishes }
How do I avoid using instance of
when wanting a description of a specific language for that dish?
Should I define for each language a get method in the dish class:getFrench(), getArabic(),..?
Or should I keep it in list and check for instance of French by looping the list and then call getDescription()
on this list object<language>
?
Or is there a way for a more polymorphic approach?