From 1b0606af7f7f0a063e9dedc3a98f344d6be80c2d Mon Sep 17 00:00:00 2001 From: Ida Made Revindra Dikta Mahendra <idamaderevindra05@gmail.com> Date: Fri, 28 Mar 2025 08:24:09 +0700 Subject: [PATCH] [DOCS]: Writing Reflection Publisher-1 --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 3043f06..602b12a 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,11 @@ This is the place for you to write reflections: ### Mandatory (Publisher) Reflections #### Reflection Publisher-1 +In the traditional Observer pattern, a Subscriber is defined as an interface (or trait in Rust) to ensure that any type acting as a subscriber implements a common set of methods. In our BambangShop case, even though we currently have only one type of subscriber represented by a single Model struct, I believe it is beneficial to use a trait. Adopting a trait now provides flexibility for future expansion; if different subscriber behaviors become necessary later on, the trait ensures that they all adhere to the same contract without requiring a complete redesign of the system. + +When considering the uniqueness of elements like the id in Program or the url in Subscriber, choosing the right data structure is critical. A simple Vec might work when the number of items is very small and operations are infrequent. However, since these identifiers need to be unique and quickly accessible, using a DashMap (which functions like a thread-safe HashMap) is more appropriate. This data structure offers faster lookups, insertions, and deletions, especially under concurrent conditions, ensuring that our system remains efficient as it scales. + +Rust’s strict safety guarantees push us to consider thread-safe data handling at every turn. In our implementation, we opted for DashMap to maintain a global list of subscribers because it inherently manages synchronization across threads. While one could consider implementing a Singleton pattern with a plain HashMap to provide a single shared instance, that approach would force us to add our own synchronization layers (using Mutex or RwLock), complicating the design. DashMap simplifies this by offering built-in, concurrent-safe operations, making it a more straightforward solution in a multithreaded environment. #### Reflection Publisher-2 -- GitLab