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
This commit is contained in:
2026-05-19 19:39:55 +05:30
parent 007927bf34
commit 56c5c2dc70
7 changed files with 21 additions and 10 deletions
@@ -7,11 +7,8 @@ class Notification;
class Subject class Subject
{ {
protected:
util::Map<std::string, User*> m_observers;
public: public:
virtual ~Subject() = default; virtual ~Subject() = default;
virtual void attach(User* user) = 0; virtual void attach(User* user) = 0;
virtual void detach(User* user) = 0; virtual void detach(User* user) = 0;
virtual void notify(Notification* notification) = 0;
}; };
@@ -116,3 +116,7 @@ void User::setState(util::State status)
{ {
m_status = status; m_status = status;
} }
void User::update(Notification* notification)
{
}
@@ -41,4 +41,5 @@ public:
void addNotification(Notification* notification); void addNotification(Notification* notification);
void setRole(util::UserType role); void setRole(util::UserType role);
void setState(util::State status); void setState(util::State status);
void update(Notification* notification) override;
}; };
@@ -10,6 +10,7 @@ class InventoryManagementService : public NotificationManagementService
{ {
private: private:
DataStore& m_dataStore; DataStore& m_dataStore;
static util::Map<std::string, User*> m_observers;
public: public:
InventoryManagementService() : m_dataStore(DataStore::getInstance()) {} InventoryManagementService() : m_dataStore(DataStore::getInstance()) {}
util::Map<std::string, InventoryItem*> getInventoryItems(); util::Map<std::string, InventoryItem*> getInventoryItems();
@@ -17,5 +18,7 @@ public:
void addInventoryItem(const std::string& partName, int quantity, double price); void addInventoryItem(const std::string& partName, int quantity, double price);
void removeInventoryItem(const std::string& inventoryItemID); void removeInventoryItem(const std::string& inventoryItemID);
void sendLowStockAlerts(); 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;
}; };
@@ -6,8 +6,8 @@
class NotificationManagementService : public Subject class NotificationManagementService : public Subject
{ {
public: public:
void sendNotification(User* recipient, const std::string& title, const std::string& message); virtual ~NotificationManagementService() = default;
void attach(User* user) override; virtual void sendNotification(User* recipient, const std::string& title, const std::string& message) = 0;
void detach(User* user) override; virtual void attach(User* user) = 0;
void notify(Notification* notification) override; virtual void detach(User* user) = 0;
}; };
@@ -12,11 +12,14 @@ class PaymentManagementService : public NotificationManagementService
{ {
private: private:
DataStore& m_dataStore; DataStore& m_dataStore;
static util::Map<std::string, User*> m_observers;
public: public:
PaymentManagementService() : m_dataStore(DataStore::getInstance()) {} PaymentManagementService() : m_dataStore(DataStore::getInstance()) {}
void generateInvoice(ServiceBooking* booking); void generateInvoice(ServiceBooking* booking);
util::Map<std::string, Invoice*> getInvoices(const std::string& customerID); util::Map<std::string, Invoice*> getInvoices(const std::string& customerID);
void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode); void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode);
void sendPaymentReminders(); 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;
}; };
@@ -13,6 +13,7 @@ class ServiceManagementService : public NotificationManagementService
{ {
private: private:
DataStore& m_dataStore; DataStore& m_dataStore;
static util::Map<std::string, User*> m_observers;
public: public:
ServiceManagementService() : m_dataStore(DataStore::getInstance()) {} ServiceManagementService() : m_dataStore(DataStore::getInstance()) {}
util::Map<std::string, Service*> getServices(); util::Map<std::string, Service*> getServices();
@@ -30,5 +31,7 @@ public:
void cancelTechnicianJobs(const std::string& technicianID); void cancelTechnicianJobs(const std::string& technicianID);
void createComboPackage(const std::string& name, const util::Vector<std::string>& serviceIDs, double discountPercentage); void createComboPackage(const std::string& name, const util::Vector<std::string>& serviceIDs, double discountPercentage);
void removeComboPackage(const std::string& comboPackageID); 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;
}; };