开发者

mitosis of a human cell

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.


Actually that's what I'm even using to clone my cells. But it's not the cloning of the cells that's my problem, it's what the method "mitosis" should return. As long as mitosis(biologically) is concerned, two identical cells are produced.

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:

    public Cell mitosis() {
        return this.clone();  // ... or equivalent
    }
    
  • a method on this Cell that returns two cells:

    public Cell[] mitosis() {
        return new Cell[]{this, this.clone()};  // ... note - must return this as one 
                                                // of the objects
    }
    
  • a static method that returns two cells:

    public static Cell[] mitosis(Cell one) {
        return new Cell[]{one, one.clone()}; 
    }
    

Even the following might be right ... if the caller takes care to remove all references to the original cell.

    public static Cell[] mitosis(Cell original) {
        return new Cell[]{original.clone(), original.clone()}; 
    }

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.


I would suggest that Cell implements Cloneable and use the copy constructor idiom on clone() method.

On doMitosis() method in Cell you basically do something like this:

public Cell[] doMitosis() {
    Cell[] cells = new Cell[]{this.clone(), this.clone()};
    return cells;
}

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.


As an alternative to Cloneable, consider a copy constructor or a copy factory, the static factory analog of a copy constructor.


This turns out to be something you have to do in real Java programs---check out the Cloneable interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜