With information from the patterns we reviews and described on Part 1 of this post we were able to identify and implement some of the patterns in our own app. This meant doing some refactoring and rethinking of some of the work I have done to date. This meant an update to my data structures as shown in my class diagrams:
I have enclosed in a group (in purple) the components that make the design patterns implemented for this assignment and described below.
I have structured the app (and moved code accordingly) to demonstrate that the app is using the MVVM design pattern.
Appropriate Groups have been created/renamed to host the files that make each to the Model, ViewModel and View
In the Observer pattern, the subscriber is the observer object and receives updates, the publisher is the observable object and sends updates. The value is the underlying object that’s changed.
I am using the Observer pattern in my
orderCaretaker class, which is part of my Memento implementation (see below). The class is marked as an observable object and contains a variable called
order that uses the
@Published property wrapper so that it can be observed from within views elsewhere in the project.
The Memento pattern enables us to save and restore an object. In this case I am implementing a Memento pattern to save the status of an user’s order. They are able to add and remove items from the stack as well as clear it and restore it.
This meant that now users can remove and add dishes to their orders, which was one of the things I mentioned as a short coming of the implementation in Week 5. You can see an extra icon in the order view below where the user can remove an item, or use the “Clear order” button at the top.
Finally, I have implemented a Builder pattern for users to be able to build their own pizza. They can chose the ingredients from Proteins, Sauces, Cheeses and Vegetables. Note that for the first three they can only choose at most one, whereas they can pick as many vegetables as they want. The Director is the JBPizzaView, the builder is presented below and the product is an instance of the Dish class which can be added to an order. The UI can be seen in the image above on the right.
What do you think?
Also published on Medium.