From: Tobias Weber Date: 2008-05-25T23:19:46+09:00 Subject: Re: How to model something In article , Mark Wilden wrote: > [Note: parts of this message were removed to make it a legal post.] ? > > I could have 'if gender' in every accessor > > That seems like the simplest approach. The person object is the one > who's creating this restriction - weight shouldn't know about gender > and gender shouldn't know about weight. Wouldn't that only affect one > accessor - weight? In the example, yes. In reality it's 3 attributes and writing is forbidden as well. I implemented it using one class and an Integer for the genders and it got pretty messy as (storage) space needs to manufacture persons and therefore write female's weight where it normally wouldn't be allowed. I worked around that using set_instance_variable but felt awful. So I rewrote everything using the state pattern, but with a Struct containing the attributes being passed around between state instances. Even uglier code. I hate Java, but its protected package access would help with this. -- Tobias Weber