I am modeling dishes that a restaurant serves. I might make a Dish class something like this:
class Dish
attr_accessor :name, :price, :ingredients, etc...
def initialize(dish_name, dish_price, etc...)
name= dish_name
price= dish_price
end
end
With respect to memory usage, would it be better to create instances of Dish for each dish, Dish.new("Chicken Curry", ...)
, or create a new class that subclasses Dish, class ChickenCurry < Dish; ...; end;
? Are there any other things to consider when choosing between these two methods with respect to hardware resources?
For clarification the ChickenCurry class would only contain a constructor where it sets the appropriate fields, like so:
class ChickenCurry < Dish
def initialize
super("Chicken Curry", ...)
end
end
Which uses more resources, Dish.new
or ChickenCurry.new
? Is the difference negligible? I plan to have thousands of these objects so even a 10 KB difference is worth considering.
I am using JRuby so please consider the JVM when answering but answers pertaining to Matz's Ruby are welcome too.
This is NOT a question about design. I'm only interested in resource usage.