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!
==Overview== The abstract factory design pattern is one of the 23 patterns described in the 1994 ''[[Design Patterns]]'' book. It may be used to solve problems such as:<ref>{{cite web|title=The Abstract Factory design pattern - Problem, Solution, and Applicability|url=http://w3sdesign.com/?gr=c01&ugr=proble|website=w3sDesign.com|access-date=2017-08-11}}</ref> * How can an application be independent of how its objects are created? * How can a class be independent of how the objects that it requires are created? * How can families of related or dependent objects be created? Creating objects directly within the class that requires the objects is inflexible. Doing so commits the class to particular objects and makes it impossible to change the instantiation later without changing the class. It prevents the class from being reusable if other objects are required, and it makes the class difficult to test because real objects cannot be replaced with mock objects. A factory is the location of a concrete class in the code at which [[object creation|objects are constructed]]. Implementation of the pattern intends to insulate the creation of objects from their usage and to create families of related objects without depending on their concrete classes.<ref name="bullet points" /> This allows for new [[Subtyping|derived types]] to be introduced with no change to the code that uses the [[base class]]. The pattern describes how to solve such problems: * [[Encapsulation (computer programming)|Encapsulate]] object creation in a separate (factory) object by defining and implementing an interface for creating objects. * Delegate object creation to a factory object instead of creating objects directly. This makes a class independent of how its objects are created. A class may be configured with a factory object, which it uses to create objects, and the factory object can be exchanged at runtime. {{See also|#UML diagram}}
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)