I am creating a population genetics simulation system in JRuby.
I have created classes such as Allele, Gene, Organism, Population.
A Population object contains multiple Organism objects (in an array), each Organism object contains multiple Genes, and so on.
Currently, it is very easy to know, for example, what Gene objects a certain Organism object has. However, if all I have is a Gene object, I do no know what Organism it belongs to.
One solution I have thought of is:
attr_accessor :name, :parent
def initialize(name, parent)
@name = name
@parent = parent #parent will be the parent object
end
If I do this, will @parent merely be a reference to the parent object in memory, or will it be a whole new object?
Is this the best way to do this? Is there another 'better' way of doing this?
Thanks!