There is no doubt that dependency injection is good, and offer several benefits. When it comes to inject dependency, there are two main ways, by using constructor and by using setter methods.
Constructor injection makes dependencies obvious
enforces order of initialization
makes wiring easy
supports testable code
more readable
enforce completeness
CreditCardProcessor ccp = new CreditCardProcessor();
OfflineQueue oq = new OfflineQueue()
Database db = new Database();
Constructor injection makes dependencies obvious
enforces order of initialization
makes wiring easy
supports testable code
more readable
enforce completeness
CreditCardProcessor ccp = new CreditCardProcessor();
OfflineQueue oq = new OfflineQueue()
Database db = new Database();
No comments:
Post a Comment
Feel free to comment, ask questions if you have any doubt.