Skip to content

Instantly share code, notes, and snippets.

@wsoczynski
Created November 24, 2011 19:07
Show Gist options
  • Save wsoczynski/1392023 to your computer and use it in GitHub Desktop.
Save wsoczynski/1392023 to your computer and use it in GitHub Desktop.
The Context 2
public class Surgeon {
private HashMap<String, MedicalProcedure> knownProcedures;
public Boolean operate(Human patient, String procedureName) throws FamilyDoesNotAllowException {
Field[] fields = Human.class.getDeclaredFields();
try {
List<Organ> organs = new ArrayList<Organ>();
for (Field field : fields) {
field.setAccessible(true);
Organ organ = (Organ)field.get(patient);
organs.add(organ);
}
MedicalProcedure procedure = knownProcedures.get(procedureName);
return procedure.execute(organs);
} catch (IllegalAccessException e) {
throw new FamilyDoesNotAllowException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment