0 votes
in Design Patterns by

Q. What is Factory pattern?

1 Answer

0 votes
by

Factory pattern is one of most used design pattern and comes under creational patterns category.

In Factory pattern, we create object without exposing the creation logic to the client and refer to newly created object using a common interface.

image


**Pro's**:

  • Allows you to hide implementation of an application seam (the core interfaces that make up your application)
  • Allows you to easily test the seam of an application (that is to mock/stub) certain parts of your application so you can build and test the other parts
  • Allows you to change the design of your application more readily, this is known as loose coupling

Con's

  • Makes code more difficult to read as all of your code is behind an abstraction that may in turn hide abstractions.
    • Can be classed as an anti-pattern when it is incorrectly used, for example some people use it to wire up a whole application when using an IOC container, instead use Dependency Injection.

Related questions

+1 vote
asked Oct 16, 2019 in Design Patterns by DavidAnderson
0 votes
asked Jul 24, 2023 in Design Patterns by SakshiSharma
...