A factory is a helper that makes the right kind of object for you so you don’t have to decide. That said, factories are polarizing because some engineers view them as examples of engineering.
Simple Factory
Factory shows up when requirements say something like “support different notification types”, e.g.,
public interface INotification
{
void Send(string message);
}
public class EmailNotification : INotification
{
public void Send(string message) { ... }
}
public class SmsNotification : INotification
{
public void Send(string message) { ... }
}
enum NotificationType { Email, Sms }
public static class NotificationFactory
{
public static INotification Create(NotificationType notificationType) =>
notificationType switch {
NotificationType.Email => new EmailNotification(),
NotificationType.Sms => new SmsNotification(),
_ => throw new ArgumentException("Unknown type")
};
}
… where clients do var notification = NotificationFactory.Create(NotificationType.Sms).
References
- Design Patterns | Hello Interview Low Level Design. www.hellointerview.com . Accessed Sep 16, 2026.
How do we provide different constructor arguments, e.g.,
NotificationFactory.Createneeds to be aware of the constructor arguments that might not be known until invocation.