Categories

Jan 27 in JAVA
Q: Which one is better constructor injection or setter dependency injection?

1 Answer

Jan 27

Each has their own advantage and disadvantage. Constructor injection guaranteed that class will be initialized with all its dependency, but setter injection provides flexibility to set an optional dependency. Setter injection is also more readable if you are using an XML file to describe dependency. Rule of thumb is to use constructor injection for mandatory dependency and use setter injection for optional dependency.

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

Related questions

Madanswer
Jan 24 in JAVA
Jun 2 in JAVA
Jan 15 in Angular
...