How to model something

-------- Original-Nachricht --------

Datum: Sat, 24 May 2008 20:09:51 +0900
Von: Tobias Weber <>
Betreff: How to model something

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

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)

  Tobias Weber

Hi Tobias,

I'd use Struct ...

Best regards,




def check_and_multiply(arg,default_value,factor)
  # return factor, if arg==default_value, else return 1
  if arg==default_value
    return factor
    return 1
class Human
  def ask_for_weight(weight_loss_factor=0.5)
    if self.gender=='female'
      return "Don't ask me this!"
      return self.weight*check_and_multiply(self.position,'space',weight_loss_factor)
  def change_sex
    if self.gender=='male'
    if self.gender=='female'
    return temp
  def change_position
    if self.position=='earth'
    if self.gender=='space'
    return temp

p woman.ask_for_weight
p man1.ask_for_weight
p man2.ask_for_weight


GMX startet Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: