The factory pattern takes the responsibility of creating an object from a client who uses it. It generates the object of classes that are following a common interface. A client has to pass only type of the implementation it wants and the factory will create that object.
If we apply the factory pattern to our balance sheet example, the process of inverting of object creation is depicted as per the following diagram:
- Client (in our case, it's a balance sheet module) talks to the factory—Hey factory, can you please give me the fetch data object? Here is the type.
- The factory takes the ...