Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Overview 🌐

The Factory Method Pattern defines an interface for creating an object but allows subclasses to decide which class to instantiate. This approach lets a class defer instantiation to subclasses, enhancing flexibility and encapsulation.

Use Case 🔍

  • Useful when there is a need to manage and maintain a large collection of smaller objects that share properties.
  • Often used in applications where management of database connections and their allocation is needed.

Implementation 🛠️

The factory_method.py file contains a Python class that demonstrates the implementation. This pattern uses a creator class with a default implementation of the factory method that returns a default object. It also allows subclasses to override this method to return different types of objects.

Example Usage 📝

creator = ConcreteCreator()
product = creator.factory_method()
print(product.operation())

Example Usage

creator = ConcreteCreator()
product = creator.factory_method()
print(product.operation())

Output 📊

Result of the ConcreteProduct operation.

This output shows how the product created by the factory method performs its operation, demonstrating the dynamic creation of objects.

Business Logic Method 🧠

Here is how you can use the Factory Method class to perform some business logic:

singleton = Singleton()
singleton.some_business_logic()

Testing 🧪

The test_factory_method.py file includes tests to ensure that the Factory Method pattern is correctly implemented and that it can dynamically create various types of product instances.