Let's assume that you wanna create a class that resembles a spreadsheet. It will have the following two functions:
cell_value_set()
cell_value_get()
cell_value_get() takes cell name as parameter and returns its value.
cell_value_set will have two inputs, both string types. The first is cell name, and the second is value that describes the cell.
For instance,
cell_value_set("C1", "12")
will set cell C1 equal to value 12
However, second value doesn't need to be numeric. It could be a function of two cells: a sum, multiplication, division, subtraction, etc.
Also, when we invoke cell_set_value to the same cell, the most recent one overrides the other. Here's an example.
cell_value_set("A1", "12")
cell_value_set("C1", "3")
cell_value_set("B1", "A1/C1") #B1 is 12/3 = 4
cell_value_get("B1") #return 4
cell_value_set("C1", "4") #now C1 becomes 4, so B1 becomes 12/4 = 3
cell_value_get("B1") #return 3
cell_value_set("B1", "C1 * A1") #now B1 becomes 123=36
cell_value_set("A1", "2") #now B1 becomes 23=6
cell_value_set("B1") #return 6
call_value_set("A1") #return 2
Now, here's important part.
cell_value_get() will be used MUCH MORE FREQUENTLY than cell_value_set()
When you create a class with those two functions, MAKE SURE to optimize it using the above guideline, so it will be much more efficient to make updates to each cell value when you get cell_value_set() and cache those values than calculate it each time cell_value_get() happens
We assume that all inputs are valid, so you don't have to worry about exceptional cases, or the functions going in cycle (for instance, if we defined C1=B1+A1, then we're not gonna redefine B1=C1+A1, which will mean B1 is an input file to C1, but then C1 is an input file to B1. Input-Output relationship is never altered. If Cell 1 is used as an input to calculate Cell 2, then Cell 2 can never be an input for Cell 1), division by zero, function having fewer than or more than two cells, some cell values not defined, etc.