From 153cbb652271d48f5f42001d0ef4038a77da0828 Mon Sep 17 00:00:00 2001 From: Andrew4Coding <andrewdevitoaryo@gmail.com> Date: Fri, 28 Mar 2025 01:05:44 +0800 Subject: [PATCH] docs: add first reflection --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 3043f06..ccf544c 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,16 @@ This is the place for you to write reflections: ### Mandatory (Publisher) Reflections #### Reflection Publisher-1 +> In the Observer pattern diagram explained by the Head First Design Pattern book, Subscriber is defined as an interface. Explain based on your understanding of Observer design patterns, do we still need an interface (or trait in Rust) in this BambangShop case, or a single Model struct is enough? + +In this case, we do not require an interface or trait because we only have a single observer, the Subscriber. Typically, interfaces or traits are used when dealing with multiple types of observers grouped into different classes. However, here, a single struct is sufficient to meet the requirements. + +> id in Program and url in Subscriber is intended to be unique. Explain based on your understanding, is using Vec (list) sufficient or using DashMap (map/dictionary) like we currently use is necessary for this case? + +Using a Dashmap is highly important in this case because it allows us to access the Subscriber by its unique URL. This is crucial for the notification process, as we need to send notifications to specific subscribers based on their URLs. If we were to use a Vec, we would have to iterate through the entire list to find the correct subscriber, which would be inefficient and time-consuming. + +> When programming using Rust, we are enforced by rigorous compiler constraints to make a thread-safe program. In the case of the List of Subscribers (SUBSCRIBERS) static variable, we used the DashMap external library for thread safe HashMap. Explain based on your understanding of design patterns, do we still need DashMap or we can implement Singleton pattern instead? +Using a static singleton DashMap ensures thread safety throughout the entire process by guaranteeing that only one thread can access the shared resource at a time. The Singleton pattern ensures that all subscribers remain synchronized effectively. #### Reflection Publisher-2 -- GitLab