I am struggling to define methods in OOP. Currently I am practicing with this scenario: "A hospital has started the development of a new system to keep records of analysis done by patients and the doctor who asked them."
I defined four classes: Patient, Doctor, Analysis and Hospital.
- Patient: represents the person who goes to the hospital. May know which analysis has done.
- Doctor: represents a professional of medicine. May know which analysis has requested.
- Analysis: represents a study requested by a specific doctor for a specific patient.
- Hospital: keeps track of doctors, patients and analysis.
Now I am not comfortable with this diagram because:
- If any method has access to a patient, then it could exec
joe.addAnalysis(a)but analysis "a" is never added to Hospital. This would generate inconsistency.
- Same as above but with doctor instead of patient.
So in my second attempt, I removed methods
getPatientAnalysis(p: Patient): Analysis[0..*]
getDoctorAnalysis(d: Doctor): Doctor[0..*]
But in this case I wouldn't be able to ask a patient for their analysis list directly. Same goes to doctors.
So the question is: Is my second attempt better? If so, then what happens with "patients knows which studies they've done"?