Doesn't the Factory template violate the "Report, Ask" principle?

The procedural code receives information, then makes decisions. Object oriented code tells objects to do something.

Alec Sharp

When we use the Factory pattern , we make a decision based on the property of the class other than the factory class, so this does not break Report, do not ask for a principle ?

+4
source share
1 answer

No, we do not violate.

When we tell the Factory class to instantiate an object, all responsibility lies with the Factory class. The caller does not affect a particular class.

The Factory class itself also does not violate this rule. He does what he has to do: on the basis of these rules (let it be hardcoded or installed externally or maybe something more complex) he decides which object to generate. But every bit of logic is inside the Factory method.

+2
source

Source: https://habr.com/ru/post/1493598/


All Articles