Hi,
my programm needs to store persons. They have a weight and a gender. You
are only allowed to ask males for their weight, females will throw
dishes/exceptions. There is a method to change someones gender.
I could have ‘if gender’ in every accessor or use the state pattern. But
that has no state, so I’m confused. I would have to access the variable
in the wrapper class.
The programm can also shoot people into space, in which case the
implementation of weight changes but the same restrictions apply.
The proxy pattern will help here, probably by having weight first call
delegate.weight, and if that isn’t NoMethodException multiplying with
gravity.
Any advice or implementations of similar problems I could look at?
(and in reality people are TV series with 6 genders and 5 other
attributes, and space is just but a remote place to store things)