我正在为我的项目用java编写遗传过程,我想模拟人类细胞的有丝分裂。人体细胞含有23对染色体。有丝分裂基本上是细胞分裂或繁殖,其中一个细胞产生两个基因相同的子细胞。您可以在这里找到有关它的图片(稍微向下滚动页面):
有丝分裂
我认为这种有丝分裂就像“Cell”类中的 java 方法。所以我用它自己的方法创建了一个类 Chromosome 来表示单个染色体,并创建了一个包含 23 对染色体的“Cell”类。我计划将有丝分裂方法放入 Cell 类中,但问题是该方法应返回 2 个相同的细胞,并且我认为不可能创建一个在此类中返回 2 个细胞的方法。
我想过创建一个返回 2 个单元格数组的方法,但它不起作用。
关于如何创建此方法有什么建议吗?或者也许是我正在使用的方法之外的另一种方法?谢谢。
I'm programming genetic processes in java for my project and I want simulate the mitosis of a human cell. A human cell contains 23 pairs of chromosome. Mitosis is basically a cell division, or reproduction, in which a cell gives rise to two genetically identical daughter cells. You can find a picture about it here (scroll a little bit down the page):
Mitosis
I think that this mitosis would be like a java method in a class "Cell" for example. So i made a class Chromosome with it's own methods to represent a single chromosome and made a class "Cell" containing 23 pairs of chromosomes. I plan on putting the method mitosis in the class Cell but the problem is that this method should return 2 identical cells and I think it's impossible to create a method that returns 2 cells in this class.
I thought about making a method that would return an array of 2 cells it doesn't work.
Any suggestions an how to create this method? Or maybe another approach than the one i'm using? Thanks.
发布评论
评论(4)
作为
Cloneable
的替代方案,请考虑复制构造函数或复制工厂,复制构造函数的静态工厂模拟。As an alternative to
Cloneable
, consider a copy constructor or a copy factory, the static factory analog of a copy constructor.事实证明,这是您在真正的 Java 程序中必须做的事情——查看 可克隆界面。
This turns out to be something you have to do in real Java programs---check out the Cloneable interface.
您正沉迷于试图让 Java 表现得像现实世界的对象一样。
您应该关注的是有丝分裂后拥有正确数量的正确类型的细胞,而不是使方法签名直接反映现实世界的事件。
有丝分裂是一个细胞分裂成两个的过程。 IMO,以下任何一个都是 Java 中的有效“模型”:
此 Cell 上返回另一个的方法:
此 Cell 上的一个方法返回两个单元格:
返回两个单元格的静态方法:
即使下面的可能是正确的......如果调用者注意删除对原始单元格的所有引用。
但我的观点是,签名是什么并不重要。重要的是,在方法(和调用者)完成这些操作之后,新模型在正确的关系中具有正确的 Cell 对象。
You are getting hung up over trying to make Java behave like a real world object.
What you should be focusing on is having the right number of the right kind of cells after mitosis, not on making the method signatures directly mirror the real-world events.
Mitosis is where one cell splits into two. IMO, any of the following are valid "models" in Java:
a method on this Cell that returns the other one:
a method on this Cell that returns two cells:
a static method that returns two cells:
Even the following might be right ... if the caller takes care to remove all references to the original cell.
But my point is that it doesn't really matter what the signatures are. What matters is that after the method (and the caller) have done there stuff, the new model has the right Cell objects in the right relationships.
我建议 Cell 实现 Cloneable 并使用 复制构造函数 习惯用法
clone()
方法。在
Cell
中的doMitosis()
方法上,您基本上会执行以下操作:PS。代码只是一个粗略的草图,而不是实际的实现。此外,此代码还考虑到父单元格必须被杀死(并进行垃圾收集),以便 2 个相同的单元格可以拥有通行权。
I would suggest that
Cell implements Cloneable
and use the copy constructor idiom onclone()
method.On
doMitosis()
method inCell
you basically do something like this:PS. Code is a rough sketch, not actual implementation. Also, this code takes into consideration that the parent cell must be killed (and garbage collected) so that the 2 identical cells can have right of way.