[Solved] Best way to initialize multiple menu items into a menu from a restaurant


  1. You have a Menu class, I assume it would be a POJO class.
  2. You have different restaurants, each restaurant has it’s own menu.

Solution:
Don’t save multiple restaurant’s menu in same menu class, have one object for one menu and yes it won’t be inefficient to do so.

Reason:

  1. The amount of data will be the same weather you store it in different objects or you save all in one. It is just that your data will be well managed and it will be independent of each other if you are having separate objects.
  2. If you store all data in one object than suppose if you are not using menu of some restaurants, even then that data will stay in the memory. where as if there are separate objects, the menu that you are not using will be garbage collected. Now, this is why using multiple objects will not be inefficient.

solved Best way to initialize multiple menu items into a menu from a restaurant