Sync Factory Method, Abstract Factory, Builder, Prototype to Java 25; fix post/code mismatches

This commit is contained in:
2026-06-23 11:00:02 +05:30
parent 2f684bf3d7
commit 2fbf89875b
51 changed files with 634 additions and 337 deletions

View File

@@ -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();
}
}