diff --git a/README.md b/README.md index 3043f06d471f2933c5a98c71ad06b7d900d6812c..602b12ace49cfe5e4314809eded85458f074b0a4 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