0

according to uncle Bob responsibility means "a reason to change".
so as factory class is responsible for creating multiple classes, if any of those classes would change (in the constructor) the factory class needs to change too.
so I'm thinking it has more than one reason to change (actually n reasons to change, n being the number of classes) hence it violates SRP.

Nikhil Vartak
  • 5,002
  • 3
  • 26
  • 32
Mohsen
  • 1,246
  • 9
  • 22
  • we use these design patterns in android and ios, don't we? although I get your point – Mohsen Jul 19 '20 at 16:47
  • 2
    sorry, my initial comment seemed a bit blunt - i was trying to explain that your question is quite general and isn't really ios/android specific, so you might get better answers if you rather ask this on software engineering instead of SO, although that's just my opinion/suggestion – a_local_nobody Jul 19 '20 at 16:53
  • thank you I think you are right @a_local_nobody – Mohsen Jul 19 '20 at 16:57
  • First note there are at least four [different factory patterns](https://stackoverflow.com/a/60285883/1371329) in popular use, so the question highly depends on which pattern you're referring to. Second note the reasons for change in the [SRP](https://stackoverflow.com/tags/single-responsibility-principle/info) are _people_ and not code, so the number of classes doesn't necessarily matter. – jaco0646 Jul 22 '20 at 02:14
  • 1
    @jaco0646 but people change the classes, it's basically the same – Mohsen Jul 22 '20 at 08:49
  • If a different person owns each class, then the number of responsibilities would equal the number of classes. If one person owns all of the classes, then the entire application has only one reason to change, i.e. when the owner changes requirements. – jaco0646 Jul 22 '20 at 13:11

1 Answers1

0

I agree - Though I have never worked with a class factory, it seems to me that it would definitely have an infinite complexity.

However, if you look at the following tutorial: Factory Design Pattern, you will see that the factory only produces extended classes from a singular interface.

So if part of the factory class simply took an array of properties and applied them to the outputted class, the complexity would be constrained to a single dimension.

Solomon Bush
  • 165
  • 9