h******e 发帖数: 52 | 1 设计一个 data structure something like excel's cell.
The cell has two types: value type and formula type (sum of other cells). My
design is as below.
Class Cell
{
rowId;
ColId;
type; //enum-> value or sum of other cells
Value; //if type is value, this field is the value, otherwise
meaningless
List cell; // if type is forumla, the field is used to show which
other cells are needed to sum
}
是不是还有更好的design? | |
d****r 发帖数: 300 | 2 Some kinda listener design pattern to catch data change event in other cells
and notifier pattern to notify other cells your data change event.
My
【在 h******e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 设计一个 data structure something like excel's cell. : The cell has two types: value type and formula type (sum of other cells). My : design is as below. : Class Cell : { : rowId; : ColId; : type; //enum-> value or sum of other cells : Value; //if type is value, this field is the value, otherwise : meaningless
|
f*******r 发帖数: 976 | 3 能否展开来讲解?
cells
设计一个 data structure something like excel's cell.
The cell has two types: value type and formula type (sum of other cells). My
design is as below.
Class Cell
{
rowId;
ColId;
type; //enum-> value or sum of other cells
Value; //if type is value, this field is the value, otherwise
meaningless
List cell; // if type is forumla, the field is used to show which
other cells are needed to sum
}
是不是还有更好的design?
【在 d****r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Some kinda listener design pattern to catch data change event in other cells : and notifier pattern to notify other cells your data change event. : : My
| |
s****9 发帖数: 2 | 4 Imagine that a cell is of formula type and its cell's value is a list of
cells. If any of cells gets changed, the parent cell should change
accordingly. It needs a notifier in child cell and a listener in parent
cell working together to do it. |
t*********r 发帖数: 387 | 5 为啥不用inheritance?
public abstract class Cell {
int getRow();
int getColumn();
notify();
}
public class Value extends Cell {
Object getValue();
}
public class Formula extends Cell {
List sums();
} | |
N********n 发帖数: 8363 | 6
你放个TYPE进去基本上要秒FAIL的。用OO思路,CLASS本身就是TYPE。应该
有个BASE CLASS CELL存通用信息,然后SUBCLASS VALUE CELL和SUBCLASS
FORMULA CELL存特定信息,从BASECLASS继承通用信息。酱紫。
【在 h******e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 设计一个 data structure something like excel's cell. : The cell has two types: value type and formula type (sum of other cells). My : design is as below. : Class Cell : { : rowId; : ColId; : type; //enum-> value or sum of other cells : Value; //if type is value, this field is the value, otherwise : meaningless
|
l*****a 发帖数: 14598 | 7 你都打算支持什么操作?
用row/column查找cell的操作在excel中应该是O(1),你这个...
My
【在 h******e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 设计一个 data structure something like excel's cell. : The cell has two types: value type and formula type (sum of other cells). My : design is as below. : Class Cell : { : rowId; : ColId; : type; //enum-> value or sum of other cells : Value; //if type is value, this field is the value, otherwise : meaningless
|
l*****a 发帖数: 14598 | 8 Formula也可以有getValue() ah, so u can put it in the base class
for notify(), I think only Value cell need that...
【在 t*********r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 为啥不用inheritance? : public abstract class Cell { : int getRow(); : int getColumn(); : notify(); : } : public class Value extends Cell { : Object getValue(); : } : public class Formula extends Cell {
|