- [x] Commit: `Implement add function in Subscriber repository.`
- [x] Commit: `Implement list_all function in Subscriber repository.`
- [x] Commit: `Implement delete function in Subscriber repository.`
- [x] Write answers of your learning module's "Reflection Publisher-1" questions in this README.
-**STAGE 2: Implement services and controllers**
- [ ] Commit: `Create Notification service struct skeleton.`
- [ ] Commit: `Implement subscribe function in Notification service.`
...
...
@@ -78,6 +78,16 @@ This is the place for you to write reflections:
#### Reflection Publisher-1
1.**Is an interface (or trait) needed in BambangShop, or a single Model struct is enough?**
In the Observer design pattern, an interface (trait) is typically used to define a contract for the `Subscriber` to ensure that all subscribers implement the required methods, such as `update`. However, in this case, we only have one type of `Subscriber` and no plans to extend it with different behaviors, so a single Model struct might suffice. Using a trait would be more beneficial if we anticipate having multiple types of subscribers with varying implementations of the `update` method.
2.**Is using Vec (list) sufficient or is DashMap (map/dictionary) necessary for unique `id` in Program and `url` in Subscriber?**
Using a `Vec` would require additional step to ensure uniqueness, such as iterating through the list to check for duplicates before adding a new item, which can be inefficient as the list grows. On the other hand, `DashMap` inherently enforces uniqueness of keys and provides efficient lookups, making it a better choice for managing unique `id` and `url` values. Moreover, `DashMap` is thread-safe, which is crucial in a concurrent environment.
3.**Do we still need DashMap or can we implement Singleton pattern instead for the List of Subscribers (SUBSCRIBERS)?**
The Singleton pattern ensures a single instance of a resource, but it does not inherently provide thread safety. On the other had, `DashMap` is specifically designed for thread-safe concurrent access to a map-like structure. Using `DashMap` simplifies the implementation of thread-safe data structure and reduces the risk of concurrency issues. Therefore, `DashMap` is a more practical choice for this case.