I want an event notification system that should notify the doctor when the heartbeat of the patient is greater than 120.I do not know, How to design such system. Just I have implemented the wrong one. Help me in implementing the correct one.
static void Main()
{
Patient[] patList = { new Patient
{ PatientID = "1", HeartBeat = 100 },
new Patient { PatientID = "2", HeartBeat = 130 } };
List<Patient> plist = patList.ToList();
Console.ReadKey(true);
}
public class Doctor
{
public event PulseNotifier AbnormalPulseRaised;
public string Name
{
get;
set;
}
}
public class Patient
{
public event PulseNotifier AbnormalPulseRaised;
static Random rnd = new Random();
public Patient()
{
PulseNotifier += new PulseNotifier(OnAbnormalPulseRaised);
}
public string PatientID
{
get;
set;
}
public int HeartBeat
{
get;
set;
}
public void HeartBeatSimulation(List<Patient> patList)
{
foreach(Patient p in patList)
{
if (p.HeartBeat > 120)
{
if (AbnormalPulseRaised != null)
{
AbnormalPulseRaised(p);
}
}
}
}
public void OnAbnormalPulseRaised(Patient p)
{
Console.WriteLine("Patient Id :{0},Heart beat {1}",
p.PatientID, p.HeartBeat);
}
}
Apart from that, I want to have a common clarification.
What is the best way to remember the publisher and observer pattern?. Because I am quite confusing about where to implement publisher and where to implement