18 lines
502 B
Java
18 lines
502 B
Java
package factorymethod;
|
|
|
|
public class Main {
|
|
public static void main(String[] args) {
|
|
System.out.println("=== Factory Method Pattern Demo ===\n");
|
|
|
|
NotificationService[] services = {
|
|
new EmailService("alice@example.com"),
|
|
new SmsService("+1-555-0123"),
|
|
new PushService("device-token-abc123")
|
|
};
|
|
|
|
for (NotificationService service : services) {
|
|
service.notifyUser("Your order #1042 has been shipped!");
|
|
}
|
|
}
|
|
}
|