Search code examples
design-patternssingle-responsibility-principle

Abstract Factory violate Single Responsibility Principle?


Tell me please, the abstract factory violates the principle of a single responsibility ? (I think that he has a lot of responsibility).


Solution

  • The Abstract Factory has a single responsibility, providing a contract for the creation of polymorphic objects without binding the interface to a specific implementation. In other words the contract is its responsibility not making the objects.

    The SRP applies to each class, the Abstract Factory is only one class in the pattern, each Concrete factory has different but similar responsibility. Do not think of a responsibility as a single function, it could be a compound.