Complete the code to create an object using a creational pattern.
object = [1]()The Factory pattern is used to create objects without specifying the exact class.
Complete the code to ensure only one instance of a class is created.
class Singleton: _instance = None def __new__(cls): if [1] is None: cls._instance = super().__new__(cls) return cls._instance
The Singleton pattern checks if the instance exists using cls._instance.
Fix the error in the Builder pattern method to return the final product.
class Builder: def __init__(self): self.product = [] def add_part(self, part): self.product.append(part) def get_result(self): return [1]
The method should return the product stored in self.product.
Fill both blanks to create a Factory method that returns a new object.
def factory_method(type): if type == 'A': return [1]() else: return [2]()
The factory method returns ProductA or ProductB objects based on the type.
Fill all three blanks to complete the Singleton pattern implementation.
class Singleton: _instance = None def __new__(cls): if [1] is None: [2] = super().__new__(cls) return [3]
All blanks refer to the class variable cls._instance to ensure only one instance is created and returned.
