I have some doubts about a constructor.
There is a class "Foo" that can be created in three different "status" we could call them "YOUNG", "ADULT" and "OLD".
I want to underline that they cannot be seen as different classes because the object will evolve and if it has been created as "YOUNG" it will become "ADULT" and then "OLD" and so on..
My question is: how can I define one or more constructors to diversify these three typologies??
I see some possibilities, but no one is an "elegant" solution..
1) Create a constructor with an int as input
public Foo(int i) { switch (i) { case 0: . . . case 1: . . . case 2: . . . } } but i do not like it because it is not so clear to understand if another person see this code.
2) Create a blank constructor and then create three different methods like
public Foo() { } public void setYoungFoo() { . . . } public void setAdultFoo() { . . . } public void setOldFoo() { . . . } This could be a clear way to resolve the problem, but i would resolve this problem in the constructor..
3) Could static variables usefull in this context?
public static final String "YOUNG"; public static final String "ADULT"; public static final String "OLD"; public Foo(String field) { } I do not know how fill this constructor because I have never used static final variables (I have seen them used in some Java classes like Calendar even if not used in the contructor).
Could you please comment these three option to underline what are their disadvantages because I am quite sure that they can not be a good solution..