Content deleted Content added
→Notes: Correct author names, book title, and publisher for Note 2. |
→Examples: fixed weasel word |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1:
{{Short description|Object-oriented software design pattern}}
In [[object-oriented programming]], the '''factory method pattern''' is a [[software design pattern|design pattern]] that uses factory methods to deal with the problem of [[object creation|creating objects]] without having to specify their exact [[class (computer programming)|classes]]. Rather than by calling a [[Constructor (object-oriented programming)|constructor]], this is accomplished by invoking a factory method to create an object. Factory methods can be specified in an [[Interface (object-oriented programming)|interface]] and implemented by subclasses or implemented in a base class and optionally [[method overriding|overridden]] by subclasses. It is one of the 23 classic design patterns described in the book ''[[Design Patterns]]'' (often referred to as the "Gang of Four" or simply "GoF") and is subcategorized as a [[creational pattern]].{{sfn|Gamma|Helm|Johnson|Vlissides|
==Overview==
Line 27:
== Examples ==
This [[C++
<syntaxhighlight lang="c++">
import std;
enum class ProductId {MINE, YOURS};
// defines the interface of objects the factory method creates.
Line 45 ⟶ 44:
public:
void print() {
std::
}
};
Line 53 ⟶ 52:
public:
void print() {
std::
}
};
|