Join our WhatsApp Channel
Cart / 0.00$

No products in the cart.

Visit Support Portal
No Result
View All Result
Friday, July 10, 2026
  • Home
  • Tutorials
  • Store
  • Managed Hosting
  • Web Development Services
  • JaggoRe AITry
Get a Free Quote
  • Login
  • Register
Neuraldemy
Friday, July 10, 2026
Cart / 0.00$

No products in the cart.

No Result
View All Result
Neuraldemy
Get A Free Quote
Home Javascript

Factory Pattern In JavaScript

Neuraldemy by Neuraldemy
March 3, 2026
in Javascript
Reading Time: 2 mins read
A A
Discuss with ChatGPTShare on WhatsAppShare on RedditShare on Twitter

A dynamic notification service (Email, SMS, Push) built to strictly adhere to SOLID principles. By using the Factory pattern and interfaces, the system avoids fragile if/else blocks and remains fully open for extension but closed for modification.

// factory pattern
interface INotification {
  send(useId: string, message: string): void;
}

class EmailNotiification implements INotification {
  public send(userId: string, message: string): void {
    console.log(`[EMAIL] Sending to user ${userId}: ${message}`);
  }
}

class SMSNotiification implements INotification {
  public send(userId: string, message: string): void {
    console.log(`[SMS] Sending to user ${userId}: ${message}`);
  }
}

class PushNotification implements INotification {
  public send(userId: string, message: string): void {
    console.log(`[PUSSH] Sending to device for user ${userId}: ${message}`);
  }
}

enum NotificationType {
  EMAIL = "EMAIL",
  SMS = "SMS",
  PUSH = "PUSH",
}

class NotificationFactory {
  public static createNotification(type: NotificationType): INotification {
    switch (type) {
      case NotificationType.EMAIL:
        return new EmailNotiification();
      case NotificationType.SMS:
        return new SMSNotiification();
      case NotificationType.PUSH:
        return new PushNotification();
      default:
        throw new Error("Invalid notification type requested");
    }
  }
}

class NotificationService {
  public notifyUser(
    type: NotificationType,
    useId: string,
    message: string,
  ): void {
    const notifier = NotificationFactory.createNotification(type);
    notifier.send(useId, message);
  }
}

const myAppService = new NotificationService();

console.log("--- System Alerts ---");
myAppService.notifyUser(
  NotificationType.EMAIL,
  "user_101",
  "Welcome to the platform!",
);
myAppService.notifyUser(
  NotificationType.SMS,
  "user_102",
  "URGENT: Server CPU is at 99%.",
);
myAppService.notifyUser(
  NotificationType.PUSH,
  "user_103",
  "Your data export is ready.",
);Code language: JavaScript (javascript)

Support

Buy author a coffee

Support
SummarizeSendShareTweetScan
Previous Post

Inside OpenAI Military Deal and the Ousting of Anthropic

Next Post

Strategy Pattern In JavaScript

Neuraldemy

Neuraldemy

This is Neuraldemy support. Subscribe to our YouTube channel for more.

Related Posts

100 CSS Interview Questions

FormData API: A Beginner’s Guide to Native Validation

Strategy Pattern In JavaScript

Inside OpenAI Military Deal and the Ousting of Anthropic

Nano Banana 2: Google’s New AI Image Generator Just Fixed the Speed vs. Quality Problem

The 5 Best Books for Learning Machine Learning Mathematics

Next Post

Strategy Pattern In JavaScript

FormData API: A Beginner’s Guide to Native Validation

100 CSS Interview Questions

Support

Buy author a coffee

Support

Top rated products

  • Probability and Statistics for Machine Learning and Data Science Probability and Statistics for Machine Learning and Data Science
    Rated 5.00 out of 5
    30.00$ Original price was: 30.00$.12.99$Current price is: 12.99$.
  • SVM Notes: Optimization & Implementation SVM Notes: Optimization & Implementation
    Rated 5.00 out of 5
    9.99$ Original price was: 9.99$.4.99$Current price is: 4.99$.
  • spidy mail hunter software Spidy Mail Hunter: Powerful And Intelligent Website & PDF Email Extractor Software (Windows App)
    Rated 4.78 out of 5
    149.00$ Original price was: 149.00$.49.00$Current price is: 49.00$.
  • Linear Algebra For Machine Learning And Data Science Linear Algebra For Machine Learning And Data Science
    Rated 4.71 out of 5
    40.00$ Original price was: 40.00$.24.99$Current price is: 24.99$.
  • Clustering and Outlier Detection A Comprehensive Tutorial Clustering and Outlier Detection 20.97$ Original price was: 20.97$.13.47$Current price is: 13.47$.

Recent Posts

100 CSS Interview Questions

FormData API: A Beginner’s Guide to Native Validation

Strategy Pattern In JavaScript

July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Mar    

Neuraldemy

Neuraldemy

Neuraldemy

Software Development

Neuraldemy helps you learn ML, AI, Web Dev and data science from scratch. Addtionally, we also provide web development and hosting services for businesses, and individuals

  • Get Started
  • Contact
  • Privacy Policy
  • Terms Of Use
  • Project Consultation
  • Support Portal
Neuraldemy

© 2026 - A learning platform by Odist Magazine

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms below to register

*By registering into our website, you agree to the Terms & Conditions and Privacy Policy.
All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
Join Our WhatsApp Channel
  • Home
  • Tutorials
  • Store
  • Managed Hosting
  • Web Development Services
  • JaggoRe AI
  • Login
  • Sign Up
  • Cart
Order Details

© 2026 - A learning platform by Odist Magazine

This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
0