Created
August 16, 2014 08:55
-
-
Save MinCha/5f979a574a96afd850e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2. Double Dispatch 방식 리팩토링 | |
NewPrescription prescription = new NewPrescription(); | |
assertEquals("two pill a day", prescription.getPrescription(new SeriousPatientStatus(), new AdultPatientType())); | |
assertEquals("one pill a day", prescription.getPrescription(new MildPatientStatus(), new AdultPatientType())); | |
assertEquals("one pill a day", prescription.getPrescription(new SeriousPatientStatus(), new ChildPatientType())); | |
assertEquals("half pill a day", prescription.getPrescription(new MildPatientStatus(), new ChildPatientType())); | |
public class NewPrescription { | |
public String getPrescription(PatientStatus status, PatientType type) { | |
return status.getPrescriptionWith(type); | |
} | |
public double getMaxIngestionPerDay(PatientStatus status, PatientType type) { | |
return status.getMaxIngrestionPerDayWith(type); | |
} | |
} | |
public class SeriousPatientStatus implements PatientStatus { | |
@Override | |
public String getPrescriptionWith(PatientType type) { | |
return type.getPrescriptionSerious(); | |
} | |
@Override | |
public double getMaxIngrestionPerDayWith(PatientType type) { | |
return type.getMaxIngrestionSerious(); | |
} | |
} | |
public class ChildPatientType implements PatientType { | |
@Override | |
public String getPrescriptionSerious() { | |
return "one pill a day"; | |
} | |
@Override | |
public double getMaxIngrestionSerious() { | |
return 1; | |
} | |
@Override | |
public String getPrescriptionMild() { | |
return "half pill a day"; | |
} | |
@Override | |
public double getMaxIngrestionMild() { | |
return 0; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment