Factory Pattern
A pattern that puts object creation in one place so callers don't pick the class.
What is Factory Pattern?
The Factory pattern puts object creation in one place. Callers ask the factory for "a notification for SMS" and get the right object back without knowing which class it is.
public static class NotificationFactory
{
public static INotification Create(string channel) => channel switch
{
"email" => new EmailNotification(),
"sms" => new SmsNotification(),
_ => throw new ArgumentException( quot;Unknown channel {channel}")
};
}
Level: Freelancer · More OOP terms at this level
Updated