|
| 1 | +# NotifyMe: Multi-Channel Notification Service 🔔 |
| 2 | + |
| 3 | +> A decoupled notification system demonstrating the **Factory Method Design Pattern** to dynamically select delivery channels (Email, SMS, Push) at runtime. |
| 4 | +
|
| 5 | +## 📖 Project Overview |
| 6 | +**NotifyMe** is a backend service designed to handle user notifications across multiple platforms. |
| 7 | + |
| 8 | +In a tightly coupled system, the main business logic would contain complex `if-else` blocks instantiating specific classes like `new SMSNotification()`. This project solves that tight coupling by implementing the **Factory Method Pattern**, allowing the application to ask for a "Notification" without needing to know the implementation details. |
| 9 | + |
| 10 | +## 🏗️ Design Pattern: Factory Method |
| 11 | +The core concept is to define an interface for creating an object, but let subclasses or a dedicated Factory decide which class to instantiate. |
| 12 | + |
| 13 | +### Key Components |
| 14 | +1. **`Notification` (Interface):** Defines the common contract (`notifyUser`) that all channels must follow. |
| 15 | +2. **`EmailNotification` / `SMSNotification`:** Concrete implementations of the interface. |
| 16 | +3. **`NotificationFactory`:** The "Decision Maker." It accepts a parameter (e.g., "SMS") and returns the correct object instance. |
| 17 | +4. **`NotificationService`:** The Client. It depends *only* on the Interface and Factory, keeping it 100% decoupled from concrete logic. |
| 18 | + |
| 19 | +## 🚀 Key Features |
| 20 | +* **Loose Coupling:** The Service layer has zero knowledge of how notifications are sent. |
| 21 | +* **Extensibility:** Adding a new channel (e.g., "Slack") requires creating one class and updating the Factory switch case—no changes to the Service or Controller are needed. |
| 22 | +* **Centralized Logic:** Object creation logic is centralized in one place (The Factory), making maintenance easy. |
| 23 | + |
| 24 | +## 🛠️ Tech Stack |
| 25 | +* **Core:** Java 21, Spring Boot 3.x |
| 26 | +* **Architecture:** Factory Method Design Pattern |
| 27 | +* **Build Tool:** Maven |
| 28 | + |
| 29 | +## 🏃 How to Run |
| 30 | + |
| 31 | +1. **Clone the repository:** |
| 32 | + ```bash |
| 33 | + git clone [https://github.com/yourusername/notifyme.git](https://github.com/yourusername/notifyme.git) |
| 34 | + ``` |
| 35 | +2. **Run the application:** |
| 36 | + ```bash |
| 37 | + mvn spring-boot:run |
| 38 | + ``` |
| 39 | +3. The server will start on `http://localhost:8080`. |
| 40 | + |
| 41 | +## 🔌 API Endpoints (Testing Guide) |
| 42 | + |
| 43 | +### 1. Send Email |
| 44 | +* **Request:** `POST /api/notify?type=EMAIL&message=Welcome+Aboard` |
| 45 | +* **Console Output:** `📧 Sending EMAIL: Welcome Aboard` |
| 46 | + |
| 47 | +### 2. Send SMS |
| 48 | +* **Request:** `POST /api/notify?type=SMS&message=Your+OTP+is+1234` |
| 49 | +* **Console Output:** `📱 Sending SMS: Your OTP is 1234` |
| 50 | + |
| 51 | +### 3. Invalid Channel (Error Handling) |
| 52 | +* **Request:** `POST /api/notify?type=FAX&message=Hello` |
| 53 | +* **Result:** `500 Internal Server Error` (IllegalArgumentException: Unknown channel: FAX) |
| 54 | + |
| 55 | +## 📝 Resume Summary |
| 56 | +* **NotifyMe Service:** Implemented the **Factory Method Design Pattern** to decouple notification logic from the main application flow. |
| 57 | +* **Architecture:** Achieved adherence to the **Open/Closed Principle**; new notification channels can be added with zero changes to existing Service business logic. |
| 58 | + |
| 59 | +--- |
| 60 | +*Created by Gautam Jain to demonstrate Clean Code principles in Spring Boot.* |
0 commit comments