Search code examples
oopcoupling

Coupling between classes


Let's assume we have two classes: Patient and MedicalExamination. We want to get all examinations for a specific patient. Which one is better:

  1. patient.getExaminations();

  2. examination.get(patient);


Solution

  • Basically, an examination cannot exist without a patient. Therefore Patient would be the root entity of the aggregate Patient - MedicalExamination, and as such Patient (or PatientRepository) would be the way to retrieve patient details and examinations:

     patient.getExaminations();