public function __construct(Patient $patient) { $this->patient = $patient; } public function attach(Doctor $doctor) { $this->listHistory[] = $doctor; } public function notify() { /** @var Doctor $doctor */ foreach ($this->listHistory as $doctor) { try { $doctor->reception($this->patient); } catch (MedicalHistoryException $e) { echo $e->getMessage(); } } } } class MedicalHistoryException extends Exception { } $patient = new Patient(100); $medicalHistory = new MedicalHistory($patient); $doctorA = new Doctor(50); $doctorB = new Doctor(50); $doctorC = new Doctor(100); $medicalHistory->attach($doctorA); $medicalHistory->attach($doctorB); $medicalHistory->attach($doctorC);