Elimizde şöyle bir hiyerarşi olsun
// Abstract Product - Buttonpublic interface Button {void render();}// Concrete Product - WindowsButtonpublic class WindowsButton implements Button {@Overridepublic void render() {System.out.println("Rendering a Windows button");}}// Concrete Product - MacButtonpublic class MacButton implements Button {@Overridepublic void render() {System.out.println("Rendering a Mac button");}}
Şöyle yaparız
// Abstract Factory public interface GUIFactory { Button createButton(); } // Concrete Factory - WindowsFactory public class WindowsFactory implements GUIFactory { @Override public Button createButton() { return new WindowsButton(); } } // Concrete Factory - MacFactory public class MacFactory implements GUIFactory { @Override public Button createButton() { return new MacButton(); } }
Hiç yorum yok:
Yorum Gönder