Q-1). What will happen if no. of products increases?

A-1). If the number of product types increases, the factory method can become bloated and harder to maintain. In that case, we have to use the Abstract Factory Pattern or break down the factory into smaller, more manageable sub-factories.

Q-2). How factory pattern violate the Open/Closed Principle?

A-2). Adding new product types often requires modifying the factory class, which violates the Open/Closed Principle. As a result, we can use a map of string keys to supplier functions or reflection to instantiate the appropriate class dynamically.

Q-3). Does implementing a Factory pattern increase the performance overhead?

A-3). The use of reflection or dynamic class loading can introduce performance overhead. As a solution, we can frequently use Cache-used objects or classes and optimize the factory method to reduce reflection usage.