Add all 23 GoF design pattern implementations
This commit is contained in:
30
01-creational/abstract-factory/Application.java
Normal file
30
01-creational/abstract-factory/Application.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package abstractfactory;
|
||||
|
||||
public class Application {
|
||||
|
||||
// The client holds references to the Abstract Factory and Abstract Products.
|
||||
// It never imports LightButton, DarkButton, or any concrete class.
|
||||
private final UIFactory factory;
|
||||
private Button submitButton;
|
||||
private TextField usernameField;
|
||||
|
||||
public Application(UIFactory factory) {
|
||||
this.factory = factory; // theme is injected; client doesn't decide
|
||||
}
|
||||
|
||||
public void buildUI() {
|
||||
// Ask the factory — get consistent products from the same family
|
||||
submitButton = factory.createButton();
|
||||
usernameField = factory.createTextField();
|
||||
}
|
||||
|
||||
public void render() {
|
||||
System.out.println("Rendering login screen:");
|
||||
usernameField.render();
|
||||
submitButton.render();
|
||||
}
|
||||
|
||||
public void simulateSubmit() {
|
||||
submitButton.onClick();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user