Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Abstract factory pattern
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Structure == === UML diagram === {{Plain image with caption|File:w3sDesign Abstract Factory Design Pattern UML.jpg|A sample UML class and sequence diagram for the abstract factory design pattern. <ref>{{cite web|title=The Abstract Factory design pattern - Structure and Collaboration|url=http://w3sdesign.com/?gr=c01&ugr=struct|website=w3sDesign.com|access-date=2017-08-12}}</ref>|700px|align=left}}{{-}} In the above [[Unified Modeling Language|UML]] [[class diagram]], the <code>Client</code> class that requires <code>ProductA</code> and <code>ProductB</code> objects does not instantiate the <code>ProductA1</code> and <code>ProductB1</code> classes directly. Instead, the <code>Client</code> refers to the <code>AbstractFactory</code> interface for creating objects, which makes the <code>Client</code> independent of how the objects are created (which concrete classes are instantiated). The <code>Factory1</code> class implements the <code>AbstractFactory</code> interface by instantiating the <code>ProductA1</code> and <code>ProductB1</code> classes. The [[Unified Modeling Language|UML]] [[sequence diagram]] shows the runtime interactions. The <code>Client</code> object calls <code>createProductA()</code> on the <code>Factory1</code> object, which creates and returns a <code>ProductA1</code> object. Thereafter, the <code>Client</code> calls <code>createProductB()</code> on <code>Factory1</code>, which creates and returns a <code>ProductB1</code> object. === Variants === The original structure of the abstract factory pattern, as defined in 1994 in ''[[Design Patterns]]'', is based on abstract classes for the abstract factory and the abstract products to be created. The concrete factories and products are classes that specialize the abstract classes using inheritance.<ref name=":0" /> A more recent structure of the pattern is based on interfaces that define the abstract factory and the abstract products to be created. This design uses native support for interfaces or protocols in mainstream programming languages to avoid inheritance. In this case, the concrete factories and products are classes that realize the interface by implementing it.<ref name="abstract factory" />
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)