I am working on a Hospital Management System and I am planning to use Strategy Pattern to manage appointment processes for different user types. The process requirements are as follows:
UserType=5
: VisitorAppointment
will be created. In this case, only the visitor will be registered and the appointment will be added to the Appointment
table as VisitorAppointment
.
UserType=6
: patient appointment will be created. In this case, a doctor within the selected department will be assigned to the patient and the appointment will be saved to the Appointment
table as ExaminationAppointment
. Also, a notification will be sent to the selected doctor via SignalR and the list of appointments that the doctor needs to attend will be updated.
Strategy Interface: An interface named IUserRegistrationStrategyService
will be defined.
Concrete Strategies:
VisitorAppointmentUserRegistrationStrategyService
: Creating a visitor appointment for UserType=5
.
ExaminationAppointmentUserRegistrationStrategyService
: Creating a patient appointment for UserType=6
, SignalR notification to the doctor after doctor selection and updating the appointment list of the doctor.
In the scenario I mentioned here, is it the right approach to apply the strategy pattern or do I need to adopt a different solution?
public interface IUserRegistrationStrategyService
{
Task ExecuteAsync(AppUser user);
}
public class DefaultUserRegistrationStrategyService : IUserRegistrationStrategyService
{
public Task ExecuteAsync(AppUser user)
{ //send mail
Console.WriteLine($"the user named {user.NameSurname} has registered.");
return Task.CompletedTask;
}
}
public class ExaminationAppointmentUserRegistrationStrategyService : IUserRegistrationStrategyService
{
public Task ExecuteAsync(AppUser user)
{
Console.WriteLine($"creating examination appointment");
Console.WriteLine($"doctor notification created with signalR");
Console.WriteLine($"doctor appointment list updated")
return Task.CompletedTask;
}
}
public class VisitorAppointmentUserRegistrationStrategyService : IUserRegistrationStrategyService
{
public Task ExecuteAsync(AppUser user)
{
Console.WriteLine($"creating visitor appointment");
return Task.CompletedTask;
}
}
public class UserRegistrationStrategyFactoryService
{
public IUserRegistrationStrategyService GetRegisterStrategy(int userType)
{
return userType switch
{
2 => new PatientUserRegistrationStrategyService(),
5 => new ExaminationAppointmentUserRegistrationStrategyService(),
6 => new VisitorAppointmentUserRegistrationStrategyService(),
_ => new DefaultUserRegistrationStrategyService()
};
}
}
I expected that by using the Strategy Pattern, I would be able to modularly handle different types of user registrations and appointment processes based on UserType. Specifically:
For UserType=5, I expected the strategy to handle visitor registration and appointment creation.
For UserType=6, I expected the strategy to handle patient registration, doctor assignment, SignalR notifications, and updating the doctor’s appointment list.
What I Am Unsure About:
I am seeking feedback on whether this approach is optimal for managing different UserType operations and if there are any improvements or alternatives that could be considered. Additionally, I would appreciate insights on:
The effectiveness of this Strategy Pattern implementation for my use case.
Any potential issues or pitfalls with this approach.
Best practices for handling such scenarios with Strategy Pattern.
Ayşe Tuluk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.