What is Factory Pattern?
Turkish: Factory Deseni
The Factory pattern moves object creation decisions into a producer component so client code stays independent of concrete classes.
What is the Factory Pattern?
The Factory pattern keeps application code from repeating the question “which class should I create and how?” in many places. Client code asks for an interface; the factory decides which concrete object to return.
How Does It Work?
Consider payment provider selection. A PaymentProviderFactory can return a Stripe, iyzico, or bank virtual POS adapter based on country, currency, or store settings. The calling code only knows the charge() method; it does not need to know construction details.
In Factory Method, subclasses decide which object to create. Abstract Factory creates families of related objects, such as theme components, database adapters, or cloud-provider clients that must work together behind consistent interfaces.
When Is It Useful?
This design pattern is useful when the object type changes at runtime, creation has multiple steps, or external service adapters should be hidden behind one interface. Shipping carriers, payment methods, report formats, and notification channels are common examples.
It is different from the Singleton pattern. Singleton manages a single shared instance; Factory organizes the decision about which object should be created.