फैक्टरी पैटर्न क्या है?
💻 coding

फैक्टरी पैटर्न क्या है?

1 min read 235 words
1 min read
ShareWhatsAppPost on X
  • 1The factory method pattern allows object creation without specifying the exact class, promoting flexibility in class design.
  • 2It is one of the 'Gang of Four' design patterns, aiding in the development of reusable and testable object-oriented software.
  • 3The pattern addresses issues of inflexibility by enabling subclasses to redefine object instantiation through a dedicated factory method.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"The factory method pattern allows object creation without specifying the exact class, promoting flexibility in class design."

फैक्टरी पैटर्न क्या है?

In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. This is done by creating objects by calling a factory method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes—rather than by calling a constructor.

The Factory Method design pattern is one of the twenty-three well-known "Gang of Four" design patterns that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse.

The Factory Method design pattern solves problems like:

How can an object be created so that subclasses can redefine which class to instantiate?

How can a class defer instantiation to subclasses?

Creating an object directly within the class that requires (uses) the object is inflexible because it commits the class to a particular object and makes it impossible to change the instantiation independently from (without having to change) the class.

The Factory Method design pattern describes how to solve such problems:

Define a separate operation (factory method) for creating an object.

Create an object by calling a factory method.

This enables writing of subclasses to change the way an object is created (to redefine which class to instantiate).

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

AskGif

Published on 1 August 2018 · 1 min read · 235 words

Part of AskGif Blog · coding

You might also like

फैक्टरी पैटर्न क्या है? | AskGif Blog