Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Someone asked me this, what will be a good aproach?

Design a model of a spreadsheet (like excel), but don’t be afraid, do it very simple!

We only need a basic class diagram with no more than 5 or 6 classes.

It should have the following features:

- The sheet will only manage numeric data

- There will be two types of cells:
- Cells that contain a fix number
- Cells that contain a formula

- The formulas are very straightforward; just support two types of operations: subtraction and addition of two cells.
Eg:
Cell A + Cell B;
Cell A - Cell B;

- Don't worry about parsing or managing the formulas as text, just suppose that you will have the three parameters separately (the operation and the two referenced cells).

- The spreadsheet will only contain one column.

- Don't worry about the graphic interface or user interactions. JUST DO THE DIAGRAM OF THE BASIC MODEL.

One possible idea is to have an element call SpreadSheet that contains a collection of Cells and the operations to set and get cells values. If you find a better approach, use it!

[edit]The following added to question as OP added it as a comment - OriginalGriff[/edit]

So far i think on adding this classes: SpreadSheet, Column, FormulaCell and NumericCell. I also will add a ICell interface. Is this a good approach? I trying to figure out the methods and properties of each classes, can someone help a newbie? - promotcompany 1 hour ago

[Edit: removed text from code block]

[edit]The following added to question as OP responded as an answer - OriginalGriff[/edit]

I was thinking in adding a Row class and add this for the spreadsheet class
Methods
AddColumn
InsertColumn
RemoveColumn

AddRow
InsertRow
RemoveRow

SelectAllRows()
UnselectAllRows()
Properties
ActiveColumn
ActiveRow
NumberOfColumns
NumberOfRows
ReadOnly

I'm on the right direction?

[edit]Don't add an answer - it only lets you know that it has happened. Edit your question so it is better illustration of what you are thinking, and comment on answers. That way we get an email to say you have done it! Cack-handed? Yes. But under development... :-D [/edit]

ASM
CAn someone helps to point me to the right direction, the question said:

The spreadsheet will only contain one column

should i add a column class or not?


I add an image of a posibble solution, is it good?

http://img543.imageshack.us/i/diagram.png/
Posted
Updated 29-Sep-10 13:26pm
v9
Comments
OriginalGriff 29-Sep-10 11:36am    
"Someone asked me this, what will be a good aproach?"
I think this translates to:
"Here is my homework: Please do it for me."
Smithers-Jones 29-Sep-10 12:19pm    
A good approach would be, to sit down and try to find a solution on your own instead of posting your homework assignment here. Then, if you have proplems, come back here, show what you did so far and where you got stuck, and people will try to help you.
Sandeep Mewara 29-Sep-10 12:19pm    
Ok. Got it. Now tell us what have you tried so far? Or lets say... your thoughts on this please?
OriginalGriff 29-Sep-10 14:57pm    
Answer changed!

1 solution

Glad to see you have thought about it!

Your proposed classes:

SpreadSheet
Column
FormulaCell
NumericCell

Plus a ICell interface.

Why? What do these classes do for you in implementing a spreadsheet? What problems might they give you in the future? What does implementing ICell as an interface help with? Or does it give you a problem in future?

These questions aren't meant to say "This is wrong - change it" but to get you to think about what you are trying to achieve. Trying to describe what you want each class for is probably the hardest bit of design - but it is also one of the most important. If you can't describe what you want it for, why is it there?

"I was thinking in adding a Row class and add this for the spreadsheet class
Methods
AddColumn
InsertColumn
RemoveColumn

AddRow
InsertRow
RemoveRow

SelectAllRows()
UnselectAllRows()
Properties
ActiveColumn
ActiveRow
NumberOfColumns
NumberOfRows
ReadOnly

I'm on the right direction?"
Getting there, I think - you have noticed you will need some symmetry between the rows and the columns, but where can you keep rows? You have a class for columns... But is that the best way to do it? Think: do you always access a spreadsheet as a whole row? Or as a whole column?

What actions do you want to take on a cell? On a row? On a column? On a whole spreadsheet?

Eh up - gotta go, the wife is calling!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900