Template Design Pattern - SENG-350-2024-fall/Team-1 GitHub Wiki

Source: app/backend/people.py, Lines 9-51.

Defines the Staff class and its shared attributes to provide a common structure for future subclasses.

class Staff:
    def __init__(self, name, role):
        self.name = name
        self.role = role

The Doctor subclass is created to extend the Staff class with an added specialty attribute.

class Doctor(Staff):
    def __init__(self, name, role, specialty, location):
        super().__init__(name, role)
        self.specialty = specialty

The EMT subclass is created to extend the Staff class again with an added activeLocation attribute.

class EMT(Staff):
    def __init__(self, name, role, activeLocation): # Change to some API that returns the active location
        super().__init__(name, role)
        self.activeLocation = activeLocation

The Nurse subclass is created to extend the Staff class again with an added location attribute.

class Nurse(Staff):
    def __init__(self, name, role, location):
        super().__init__(name, role)
        self.location = location

The Template Design Pattern is effectively used in the Staff class and its subclasses (Doctor, EMT, and Nurse). The Staff class provides a common interface and structure for shared attributes and behaviors (e.g., name, role, and login method) that all staff types need. Each subclass then builds on this template, adding specific attributes such as specialty for Doctor or activeLocation for EMT. This pattern is a good choice here because it allows consistent and reusable code for shared functionality across different staff roles, while also supporting easy customization for each role’s unique attributes. By using this structure, the system maintains flexibility and extensibility, making it simple to add new staff types in the future without modifying the core logic.