Milestone 3: Design Patterns - SENG-350-2024-fall/Team3 GitHub Wiki
- Model-View-Template (MVT) Pattern
This pattern separates the application into three main components: Model, View, and Template. This way it is easier to organize the project and work around it quite simply. In our project, this was done mainly because we picked Django to build this project on. In Django, this is exactly how projects are organized. In our models.py we have all the data and business logic, in views.py we handle the UI and presentation logic, and in our Template folder, all the HTML templates and structure of the website are there.
- Decorator Pattern
The Decorator Pattern allows us to add behavior to existent objects, dynamically, while not affecting the behavior of other objects from the same class. In our project, this can be seen whenever we use @login_required, as an authentication check.
- Form-View Pattern
The FV Pattern provides a way to handle forms in a more structured way. It allows us to abstract the form and create modularity so we can utilize them in various places in our program. For instance, in the user sign-up form, we implement the Form-View pattern by creating an instance of our sign-up form in our views.py file and rendering the form inside the signup.html file.
- Strategy Pattern
The Strategy Pattern is used to abstract and encapsulate algorithms into a group that executes a particular algorithm during runtime. This pattern allows the program to select the necessary algorithm for specific cases in our code. This design pattern is implemented in the triage.html javascript, where we encapsulate the algorithms for selecting the set of triage questions that need to be asked based on previous question responses. During runtime, a particular algorithm is selected based on the user input.
- Factory Pattern
The Factory Pattern provides a way to create objects without specifying the exact class of the object being created. This way this object's class can vary based on certain behaviors or conditions. We've implemented this design pattern in factories.py and utilized it in forms.py for the user creation functionality. In factories.py, we've created a user factory to create different types of users. Currently, the only type of user that can be created is the patient, but additional users such as admins, nurses and paramedics can be easily implemented when the database supports those types of users. We utilize this factory class in the SignupForm in forms.py.