I'm searching for an elegant and most of all "performance careful" way to use laugh()
to call maleLaugh() or femaleLaugh(). There is a way to avoid a check each laugh()
call?
I'm sure there is a design pattern for this.
public class Person {
boolean gender;
public Person(boolean gender){
this.gender = gender;
}
public void laugh(){
//--based on this.genderI call maleLaugh() or femaleLaugh()
}
public void maleLaugh(){
System.out.println("muhahahaha");
}
public void femaleLaugh(){
System.out.println("hihihihihi");
}
}