I just could not figure out which design template I should accept here. Let's say I have a class as follows:
class Person
String role;
public void takeRole(String role) {
this.role = role;
}
public void do() {
switch(role)
case a:
do this and that;
this.role = b;
case b:
do this and that;
case c:
do this and that;
this.role=a;
....
In short, a person has roles, and the do () method depends on what his role is. In some cases, he may have to switch roles. I think this () should be abstracted (especially since there may be other roles in the future) --- but how? Should there be a role class?
Any help would be appreciated.
Edit:
, , . . ( , ) . : Person (, PersonTypeA, personTypeB ..) , (, ! --- , .
, ; (1) , ( , ) , (). , role_A_1 role_A_2. , .
, , , .