class Project: def __init__(self, name, start_date, end_date): self.name = name self.start_date = start_date self.end_date = end_date def create_project(name, start_date, end_date): return Project(name, start_date, end_date) # Example Usage: my_project = create_project("My Project", "2022-01-01", "2022-02-01") print(my_project.name) # Output: My Project
class Project: def __init__(self, name, start_date, end_date): self.name = name self.start_date = start_date self.end_date = end_date class ProjectFactory: def create_project(self, name, start_date, end_date): return Project(name, start_date, end_date) # Example Usage: factory = ProjectFactory() my_project = factory.create_project("My Project", "2022-01-01", "2022-02-01") print(my_project.name) # Output: My ProjectIn this example, we have used a class-based approach to implement the Factory pattern. The `ProjectFactory` class takes in arguments and returns an instance of the `Project` class. Both examples above are using Python's built-in libraries and do not require any additional package or library installation.