Suppose I want a class called Num that contains a number, its half, and square.
I should be able to modify any of the three variables, and this will affect all member variables associated with it. I should be able to instantiate a class with any of three values.
What is the best way to design this class so that it can be easily modified and so that I don't leave anything behind?
Should I store all three numbers or just store the main number?
For example, here is how I will use my class in Python:
num = Num(5) print num.n, num.half, num.square
And that should print 5, 2.5 and 25
It is simple, but I also want to initialize half of it.
num = Num(half=2.5) print num.n, num.half, num.square
And it should also print 5, 2.5 and 25
How can I make the init function know that it is half?
And I also want to change any number, and it will change all the associated numbers! For instance:
num.square = 100 print num.n, num.half, num.square
And that should print 10, 5 and 100.
How can I design a class?