|
A software design pattern, the Abstract Factory Pattern provides a way to encapsulate a group of individual factories that have a common theme. In normal usage, the client software would create a concrete implementation of the abstract factory and then use the generic interfaces to create the concrete objects that are part of the theme. The client does not know (nor care) about which concrete objects it gets from each of these internal factories since it uses only the generic interfaces of their products. This pattern separates the details of implementation of a set of objects from its general usage. In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. ...
The factory method pattern is an object-oriented design pattern. ...
An interface defines the communication boundary between two entities, such as a piece of software, a hardware device, or a user. ...
In strictly mathematical branches of computer science the term object is used in a purely mathematical sense to refer to any thing. While this interpretation is useful in the discussion of abstract theory, it is not concrete enough to serve as a primitive datatype in the discussion of more concrete...
In computing, a client is a system that accesses a (remote) service on another computer by some kind of network. ...
An example of this would be an abstract factory class DocumentCreator that provides interfaces to create a number of products (eg. createLetter() and createResume()). The system would have any number of derived concrete versions of the DocumentCreator class like FancyDocumentCreator or ModernDocumentCreator, each with a different implementation of createLetter() and createResume() that would create a corresponding object like FancyLetter or ModernResume. Each of these products is derived from a simple abstract class like Letter or Resume of which the client is aware. The client code would get an appropriate instantiation of the DocumentCreator and call its factory methods. Each of the resulting objects would be created from the same DocumentCreator implementation and would share a common theme (they would all be fancy or modern objects). The client would need to know how to handle only the abstract Letter or Resume class, not the specific version that it got from the concrete factory. In strictly mathematical branches of computer science the term object is used in a purely mathematical sense to refer to any thing. While this interpretation is useful in the discussion of abstract theory, it is not concrete enough to serve as a primitive datatype in the discussion of more concrete...
In object-oriented programming, a class consists of encapsulated instance variables and subprograms, the methods mentioned below. ...
In computing, a client is a system that accesses a (remote) service on another computer by some kind of network. ...
Instantiation may be Philosophy: A concept in Platonism, see idea Instantiation principle - the idea that if properties exist, the essence that has the properties must necessarily exist Universal instantiation and existential instantiation, two rules of inference in logic Instantiation (computer science), A concept in object-oriented programming; see Object (computer...
A Factory method is a static method of a class that constructs another instance of an object. ...
In software development, a Factory is the location in the code at which objects are constructed. The intent in employing the pattern is to insulate the creation of objects from their usage. This allows for new derived types to be introduced with no change to the code that uses the base class. âSoftware developmentâ redirects here. ...
In computer science, the object lifetime (or life cycle) of an object in object-oriented programming is the time between an objects creation (also known as instantiation or construction) till the object is no longer used, and is destructed or freed. ...
A derived type is a type given a new type but structurally the same as the original type. ...
In computer science, a superclass is a class from which other classes are derived. ...
Use of this pattern makes it possible to interchange concrete classes without changing the code that uses them, even at runtime. However, employment of this pattern, as with similar design patterns, incurs the risk of unnecessary complexity and extra work in the initial writing of code. In computer science, runtime or run time describes the operation of a computer program, the duration of its execution, from beginning to termination (compare compile time). ...
In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. ...
How to use it
The factory determines the actual concrete type of object to be created, and it is here that the object is actually created (in C++, for instance, by the new operator). However, the factory only returns an abstract pointer to the created concrete object. In strictly mathematical branches of computer science the term object is used in a purely mathematical sense to refer to any thing. While this interpretation is useful in the discussion of abstract theory, it is not concrete enough to serve as a primitive datatype in the discussion of more concrete...
In mathematics, an operator is a function that performs some sort of operation on a number, variable, or function. ...
It has been suggested that Software pointer be merged into this article or section. ...
This insulates client code from object creation by having clients ask a factory object to create an object of the desired abstract type and to return an abstract pointer to the object. In computer science, the object lifetime (or life cycle) of an object in object-oriented programming is the time between an objects creation (also known as instantiation or construction) till the object is no longer used, and is destructed or freed. ...
In object-oriented computer programming, a factory object is an object for creating other objects. ...
In software engineering, an abstract type is a type in a nominative type system which is declared by the programmer, and which has the property that it contains no members which are also not members of some declared subtype. ...
As the factory only returns an abstract pointer, the client code (which requested the object from the factory) does not know - and is not burdened by - the actual concrete type of the object which was just created. However, the type of a concrete object (and hence a concrete factory) is known by the abstract factory; for instance, the factory may read it from a configuration file. The client has no need to specify the type, since it has already been specified in the configuration file. In particular, this means: - The client code has no knowledge whatsoever of the concrete type, not needing to include any header files or class declarations relating to the concrete type. The client code deals only with the abstract type. Objects of a concrete type are indeed created by the factory, but the client code accesses such objects only through their abstract interface.
- Adding new concrete types is done by modifying the client code to use a different factory, a modification which is typically one line in one file. (The different factory then creates objects of a different concrete type, but still returns a pointer of the same abstract type as before - thus insulating the client code from change.) This is significantly easier than modifying the client code to instantiate a new type, which would require changing every location in the code where a new object is created (as well as making sure that all such code locations also have knowledge of the new concrete type, by including for instance a concrete class header file). If all factory objects are stored globally in a singleton object, and all client code goes through the singleton to access the proper factory for object creation, then changing factories is as easy as changing the singleton object.
In computer programming, particularly in the C and C++ programming languages, a header file or include file is a file, usually in the form of source code, that is automatically included in another source file by the compiler. ...
An abstraction layer is a way of hiding the implementation details of a particular set of functionality. ...
In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. ...
Structure The class diagram of this design pattern is as shown below: Hierarchy of UML 2. ...
Image File history File links No higher resolution available. ...
Examples /* * GUIFactory example */ abstract class GUIFactory { public static GUIFactory getFactory() { int sys = readFromConfigFile("OS_TYPE"); if (sys == 0) { return new WinFactory(); } else { return new OSXFactory(); } } public abstract Button createButton(); } class WinFactory extends GUIFactory { public Button createButton() { return new WinButton(); } } class OSXFactory extends GUIFactory { public Button createButton() { return new OSXButton(); } } abstract class Button { public abstract void paint(); } class WinButton extends Button { public void paint() { System.out.println("I'm a WinButton: "); } } class OSXButton extends Button { public void paint() { System.out.println("I'm an OSXButton: "); } } public class Application { public static void main(String[] args) { GUIFactory factory = GUIFactory.getFactory(); Button button = factory.createButton(); button.paint(); } // Output is either: // "I'm a WinButton:" // or: // "I'm an OSXButton:" } Java language redirects here. ...
/* * GuiFactory example */ /* * Note how the abstract (base) class GuiFactory is the one * that instantiates its own subclasses (WinFactory, OSXFactory). * As those subclasses inherit from base and override base CreateButton method, * it’s GuiFactory's job to disambiguate who’s overriding its CreateButton method, * at the time of being instantiated by Client. * Adding more factory subclasses (e.g. LinuxFactory) confines change * to GUIFactory class only */ abstract class GuiFactory { public static GuiFactory GetFactory() { int sys = ReadFromConfigFile("OS_TYPE"); if (sys == 0) { return new WinFactory(); } else { return new OSXFactory(); } } public abstract Button CreateButton(); } class WinFactory : GuiFactory { public override Button CreateButton() { return new WinButton(); } } class OSXFactory : GuiFactory { public override Button CreateButton() { return new OSXButton(); } } abstract class Button { public string Caption; public abstract void Paint(); } class WinButton : Button { public override void Paint() { Console.WriteLine("I'm a WinButton: " + Caption); } } class OSXButton : Button { public override void Paint() { Console.WriteLine("I'm an OSXButton: " + Caption); } } class Application { static void Main() { GuiFactory factory = GuiFactory.GetFactory(); Button button = factory.CreateButton(); button.Caption = "Play"; button.Paint(); } // Output is either: // "I'm a WinButton: Play" // or: // "I'm an OSXButton: Play" } C# (pronounced see-sharp) is an object-oriented programming language developed by Microsoft as part of their . ...
interface guiFactory predicates createButton : () -> button NewButton. createEdit : () -> edit Edit. end interface guiFactory class winFactory : guiFactory end class winFactory implement winFactory clauses createButton() = winButton::new(). clauses createEdit() = winEdit::new(). end implement winFactory class osxFactory : guiFactory end class osxFactory implement osxFactory clauses createButton() = osxButton::new(). clauses createEdit() = osxEdit::new(). end implement osxFactory (The goal here is just for illustrative purposes; in a real program the GUI system would have to be initialized, and the button must be drawn somewhere.) Visual Prolog, also formerly known as PDC Prolog and Turbo Prolog, is a strongly typed object-oriented extension of Prolog. ...
goal if 1 = config::getAttribute("OS_TYPE") then GuiFactory = winFactory::new() else GuiFactory = osxFactory::new() end if, Button = GuiFactory:createButton(), Button:setText("Play"), Button:paint(). <?php /** * GUIFactory example * Taken from the Java example */ abstract class GUIFactory { /** * Returns a sub-factory * * @return GUIFactory */ static function getFactory() { $win = strpos($_ENV['OS'], 'Windows') === 0; if ($win) { return new WinFactory(); } else { return new OSXFactory(); } } /** * Create a button * @return Button */ abstract function createButton(); } /** * Windows */ class WinFactory extends GUIFactory { /** * @return WinButton */ function createButton() { return new WinButton(); } } /** * OSX */ class OSXFactory extends GUIFactory { /** * @return OSXButton */ function createButton() { return new OSXButton(); } } /** * Button */ abstract class Button { /** @var string */ private $_caption = ""; abstract function paint(); /** * Get the caption * @return string */ function getCaption(){ return $this->_caption; } /** * Set the caption * @param string Caption */ function setCaption($caption){ $this->_caption = $caption; } } class WinButton extends Button { function paint() { print("I'm a WinButton: " . $this->getCaption() . ""); } } class OSXButton extends Button { function paint() { print("I'm an OSXButton: " . $this->getCaption() . ""); } } //--- main $aFactory = GUIFactory::getFactory(); /** @var $aFactory GUIFactor */ $aButton = $aFactory->createButton(); $aButton->setCaption("Play"); $aButton->paint(); //output is //I'm a WinButton: Play //or //I'm an OSXButton: Play ?> Wikipedia does not yet have an article with this exact name. ...
See also In computer science, the object lifetime (or life cycle) of an object in object-oriented programming is the time between an objects creation (also known as instantiation or construction) till the object is no longer used, and is destructed or freed. ...
In object-oriented programming, a class consists of encapsulated instance variables and subprograms, the methods mentioned below. ...
The factory method pattern is an object-oriented design pattern. ...
In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. ...
External links | Design patterns in Design Patterns | Creational: Abstract factory • Builder • Factory • Prototype • Singleton In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. ...
This article is about the book by Gamma et al. ...
The Builder Pattern is a software design pattern. ...
The factory method pattern is an object-oriented design pattern. ...
A prototype pattern is a creational design pattern used in software development when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. ...
In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. ...
Structural: Adapter • Bridge • Composite • Decorator • Façade • Flyweight • Proxy In computer programming, the adapter design pattern (often referred to as the wrapper pattern or simply a wrapper) adapts one interface for a class into one that a client expects. ...
The bridge pattern is a design pattern used in software engineering which is meant to decouple an abstraction from its implementation so that the two can vary independently (Gamma et. ...
This does not cite any references or sources. ...
In object-oriented programming, a decorator pattern is a design pattern. ...
The façade pattern is an object-oriented design pattern. ...
Flyweight is a software design pattern. ...
// In computer programming, the proxy pattern is a software design pattern. ...
Behavioral: Chain of responsibility • Command • Interpreter • Iterator • Mediator • Memento • Observer • State • Strategy • Template method • Visitor In Object Oriented Design, the chain-of-responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects. ...
In object-oriented programming, the Command pattern is a design pattern in which objects are used to represent actions. ...
In computer programming, the interpreter pattern is a particular design pattern. ...
In object-oriented programming, an iterator is an object allowing one to sequence through all of the elements or parts contained in some other object, typically a container or list. ...
The mediator pattern is a software design pattern that provides a unified interface to a set of interfaces in a subsystem. ...
The memento pattern is a software design pattern that provides the ability to restore an object to its previous state (undo by rollback). ...
The observer pattern (sometimes known as publish/subscribe) is a design pattern used in computer programming to observe the state of an object in a program. ...
A behavioral software design pattern, state pattern is used in computer programming to represent the state of an object. ...
In computer programming, the strategy pattern is a particular software design pattern, whereby algorithms can be selected on-the-fly at runtime. ...
Template method: UML class diagram. ...
In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure. ...
| |