所以我需要設計類似的東西:設計問題 - 觀察者,工廠,組成多
我有可能含有大量的紙張(可能的不同種類)的電子表格。
每一薄板上有假設1A-9Z細胞。
在每個小區我可以有一個以上: 字符串, 號, 式 - 這意味着所述細胞獲取的操作,例如+, - ,/ *等...和細胞數, 並在細胞我有操作的結果。
我需要設計的類,所以在未來我可以添加細胞的其它類型(除了串/數字/式),也可以添加不同類型的操作,以式 - 所有以容易的方式。
ü會怎麼設計呢?
我雖然對這樣的事情:
class SpreadSheet
{
private:
vector<Isheet> sheets;
public:
write(Isheet sheet,int CellNum,ICell value);
GetValue(Isheet sheet,int CellNum,ICell value);
AddSheet(ISheet sheet);
};
class Isheet
{
vector<ICell> cells; // can i do something like that ? cause ICell is a template
};
template<class T>
class ICell
{
Vector<Iobserver> observers;
public:
T GetValue() {return m_value;};
SetValue(T val) {m_value=val;};
AddObserver(Iobserver obs);
NotifyAll();
GetPos() {return m_pos;};
private:
T m_value;
int m_pos;
};
class CInt : public ICell<int>
{
};
class CString : public ICell<std:string>
{
};
class CFormula : public ICell<int>, Iobserver
{
};
class Iobserver
{
Update(int pos);
};
,無論如何,我真的不知道我應該創建單元格混凝土類(CINT,CString的,CFormula),我應該使用某種工廠的?在哪裏放工廠?在ISheet中? 和我最關心的,我應該在哪裏計算的CFormula細胞正確的結果? 我使用觀察者模式來保持公式單元格在其他單元格更改的情況下更新。
任何建議將是巨大的