I have a factory that makes objects that depend on an external object, do I pass it in the constructor of the factory?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because Factory Method calls object connstructor you should pass all necessary paramenters to factory method. Consider folowing:
Another alternative, as aaronls suggests, you can use Inversion of Control to reduce such dependencies.