From 56c5c2dc709dbb2476fe362a95e822c1ec55ee0b Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Tue, 19 May 2026 19:39:55 +0530 Subject: [PATCH] Refactor notification service abstraction - Removed observer map from Subject base class - Removed notify() from Subject interface - Made NotificationManagementService abstract with pure virtual methods - Added static observer maps to notification service implementations - Added attach() and detach() overrides in inventory, payment, and service management services - Added update() override in User model for observer pattern support - Updated notification method declarations with override specifiers --- .../Trenser.VehicleServiceSystem/core/patterns/Subject.h | 3 --- .../Trenser.VehicleServiceSystem/models/User.cpp | 4 ++++ .../Trenser.VehicleServiceSystem/models/User.h | 1 + .../services/InventoryManagementService.h | 5 ++++- .../services/NotificationManagementService.h | 8 ++++---- .../services/PaymentManagementService.h | 5 ++++- .../services/ServiceManagementService.h | 5 ++++- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/core/patterns/Subject.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/core/patterns/Subject.h index add51b7..309a59d 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/core/patterns/Subject.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/core/patterns/Subject.h @@ -7,11 +7,8 @@ class Notification; class Subject { -protected: - util::Map m_observers; public: virtual ~Subject() = default; virtual void attach(User* user) = 0; virtual void detach(User* user) = 0; - virtual void notify(Notification* notification) = 0; }; \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.cpp index 70d1ec8..52d85a9 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.cpp @@ -116,3 +116,7 @@ void User::setState(util::State status) { m_status = status; } + +void User::update(Notification* notification) +{ +} diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.h index b03fc81..bde21e1 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/User.h @@ -41,4 +41,5 @@ public: void addNotification(Notification* notification); void setRole(util::UserType role); void setState(util::State status); + void update(Notification* notification) override; }; diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.h index 9008824..099b964 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.h @@ -10,6 +10,7 @@ class InventoryManagementService : public NotificationManagementService { private: DataStore& m_dataStore; + static util::Map m_observers; public: InventoryManagementService() : m_dataStore(DataStore::getInstance()) {} util::Map getInventoryItems(); @@ -17,5 +18,7 @@ public: void addInventoryItem(const std::string& partName, int quantity, double price); void removeInventoryItem(const std::string& inventoryItemID); void sendLowStockAlerts(); - void sendNotification(User* user, const std::string& title, const std::string& message); + void sendNotification(User* user, const std::string& title, const std::string& message) override; + void attach(User* user) override; + void detach(User* user) override; }; diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/NotificationManagementService.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/NotificationManagementService.h index 7dde4f2..b193b1d 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/NotificationManagementService.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/NotificationManagementService.h @@ -6,8 +6,8 @@ class NotificationManagementService : public Subject { public: - void sendNotification(User* recipient, const std::string& title, const std::string& message); - void attach(User* user) override; - void detach(User* user) override; - void notify(Notification* notification) override; + virtual ~NotificationManagementService() = default; + virtual void sendNotification(User* recipient, const std::string& title, const std::string& message) = 0; + virtual void attach(User* user) = 0; + virtual void detach(User* user) = 0; }; diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.h index 1b0d89a..56a2fd2 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.h @@ -12,11 +12,14 @@ class PaymentManagementService : public NotificationManagementService { private: DataStore& m_dataStore; + static util::Map m_observers; public: PaymentManagementService() : m_dataStore(DataStore::getInstance()) {} void generateInvoice(ServiceBooking* booking); util::Map getInvoices(const std::string& customerID); void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode); void sendPaymentReminders(); - void sendNotification(User* user, const std::string& title, const std::string& message); + void sendNotification(User* user, const std::string& title, const std::string& message) override; + void attach(User* user) override; + void detach(User* user) override; }; diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.h index dcef432..85e05ed 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.h @@ -13,6 +13,7 @@ class ServiceManagementService : public NotificationManagementService { private: DataStore& m_dataStore; + static util::Map m_observers; public: ServiceManagementService() : m_dataStore(DataStore::getInstance()) {} util::Map getServices(); @@ -30,5 +31,7 @@ public: void cancelTechnicianJobs(const std::string& technicianID); void createComboPackage(const std::string& name, const util::Vector& serviceIDs, double discountPercentage); void removeComboPackage(const std::string& comboPackageID); - void sendNotification(User* user, const std::string& title, const std::string& message); + void sendNotification(User* user, const std::string& title, const std::string& message) override; + void attach(User* user) override; + void detach(User* user) override; };