Sync Factory Method, Abstract Factory, Builder, Prototype to Java 25; fix post/code mismatches
This commit is contained in:
@@ -1,22 +1,16 @@
|
||||
package abstractfactory;
|
||||
|
||||
// Entry point: the ONLY place that knows the theme
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("=== Abstract Factory Pattern Demo ===\n");
|
||||
|
||||
String os = System.getProperty("os.name", "Windows").toLowerCase();
|
||||
GUIFactory factory = os.contains("mac") ? new MacFactory() : new WindowsFactory();
|
||||
|
||||
System.out.println("Detected OS family: " + (os.contains("mac") ? "Mac" : "Windows"));
|
||||
System.out.println();
|
||||
// Production: read theme from config or OS preference
|
||||
String theme = System.getProperty("app.theme", "light");
|
||||
UIFactory factory = "dark".equals(theme) ? new DarkThemeFactory() : new LightThemeFactory();
|
||||
|
||||
Application app = new Application(factory);
|
||||
app.buildUI();
|
||||
app.render();
|
||||
app.simulateClick();
|
||||
|
||||
System.out.println("\n--- Forcing Mac UI ---");
|
||||
Application macApp = new Application(new MacFactory());
|
||||
macApp.render();
|
||||
macApp.simulateClick();
|
||||
app.simulateSubmit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user