1 Answer

0 votes
by

Though both patterns help to take out object creation part from application logic, use of dependency injection results in cleaner code than factory pattern. By using dependency injection, your classes are nothing but POJO which only knows about dependency but doesn't care how they are acquired. In the case of factory pattern, the class also needs to know about factory to acquire dependency. hence, DI results in more testable classes than factory pattern. Please see the answer for a more detailed discussion on this topic.

Click here to read more about JAVA
Click here to read more about Insurance

Related questions

0 votes
asked Oct 17, 2019 in Design Patterns by Robin
0 votes
asked Jan 27, 2020 in JAVA by rahuljain1
+1 vote
asked Jan 15, 2020 in Angular by rahuljain1
0 votes
asked May 14, 2019 in Other by Robindeniel
0 votes
asked Aug 12, 2020 in Design Patterns by RShastri
...