Hey,
So i need to design something like that :
I have a spreadsheet which can contain numerous sheets (maybe of different kinds).
each sheet has let's say 1A-9Z cells.
in each cell i can have one the above : String, Number, Formula - which means the cell gets an operation like +,-,/,* etc... and cells numbers, and in the cell i have the result of the operation.
I need to design the classes, so in the future i can add other type of cells (besides string/number/formula) and add also different kind of operation to the formula - all in an easy manner.
how would u design it ?
I though about something like this :
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);
};
anyway, i'm really not sure where should i create the cell Concrete classes (CInt,Cstring,CFormula), should i use some kind of factory ? where to put the factory ? inside ISheet ? and my main concern, where should i calculate the the right result for a CFormula cell ? i used the observer pattern to keep the formula cell updated in case of other cell's changes.
any advices would be great