Spreadsheet subclass: #LinkedSpreadsheet
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Spreadsheets'!


!LinkedSpreadsheet methodsFor: 'illegal'!

cell: whatever
        " this operation is illegal with linked spreadsheets, so block it"
        self informIllegal.!

cell: whatever put: whateverElse
        " this operation isn't allowed for linked spreadsheets, so block it"
        self informIllegal.!

cells: whatever
        "this operation isn't legal for linked spreadsheets, so block it."
        self informIllegal.!

informIllegal
        "inform the user that an illegal operation has been attempted"
        DialogView warn: 'The cell: message is not valid for linked spreadsheets.'.! !

!LinkedSpreadsheet methodsFor: 'update'!

update: aspectSymbol
        "when we receive a broadcast informing us that #value has changed, update our own value"
        (aspectSymbol = #value) ifTrue:
                [ ^self updateValue ].! !

LinkedSpreadsheet subclass: #LinkedSumSpreadsheet
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Spreadsheets'!


!LinkedSumSpreadsheet methodsFor: 'operations'!

updateValue
        "calculate the sum of the linked spreadsheets' values"

        value := 0.
        mySpreadSheet do:
                [ :cell | value := value + (cell value). ].
        self value: value.
        ^value.! !

LinkedSpreadsheet subclass: #LinkedAverageSpreadsheet
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Spreadsheets'!


!LinkedAverageSpreadsheet methodsFor: 'operations'!

updateValue
        "calculate the average of the linked spreadsheets' values"

        value := 0.
        mySpreadSheet do:
                [ :cell | value := value + (cell value). ].
        self value: (value / (mySpreadSheet size)).
        ^value.! !

LinkedAverageSpreadsheet subclass: #LinkedCellSumSpreadsheet
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Spreadsheets'!


!LinkedCellSumSpreadsheet methodsFor: 'operations'!

updateValue
        "calculate the sum of the linked spreadsheets' cells' values"

        value := 0.
        mySpreadSheet do:
                [ :SheetCell | value := value + ((SheetCell sheet) cell: (SheetCell cell)). ].
        self value: value.
        ^value.! !

LinkedAverageSpreadsheet subclass: #LinkedCellAverageSpreadsheet
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Spreadsheets'!


!LinkedCellAverageSpreadsheet methodsFor: 'operations'!

updateValue
        "calculate the average of the linked spreadsheets' cells' values"

        value := 0.
        mySpreadSheet do:
                [ :SheetCell | value := value + ((SheetCell sheet) cell: (SheetCell cell)). ].
        self value: (value / (mySpreadSheet size)).
        ^value.! !