php - Too much dependency injection? -


i'm re-factoring large application quite bit of spaghetti legacy code more structured , easy maintain, , importantly, testable. can see injecting classes dependencies them opposed mixing object creation business logic makes writing unit tests easier.

i've read comments effect of "using dependency injection improperly causes more problems solves." mean? such sophisticated verbiage, dependency injection seems pretty simple concept. how abuse idea of sending dependencies in through constructor rather instantiating them within dependent class? why latter ever preferable?

all can see right makes isolating functionality write tests , mocking objects extremely easy. seems making ridiculously obvious when class has many responsibilities , points directly @ classes need refactored. getting carried away if i'm avoiding use of new keyword anywhere other di container (with exception of core php classes)?

i wouldn't worry going overboard dependency injection. have stated of benefits have seen adopting (test-ability, encouraging design re separation of concerns).

a criticism have heard made of dependency injection (and ioc) can introduce complexity. while possible over-complicate things due bad implementation, can not agree complaint intrinsic problem dependency injection.

the thing keep eye on choose the right level of abstraction , indirection dependencies give the flexibility need. many levels of indirection can add complexity no value, argue orthogonal issue dependency injection.

see this related question more possible downsides dependency injection :)


regarding issue of many dependencies included in original question prior editing:

having many dependencies can code smell, , things focus on address should be:

it sounds have tackled part of problem following these principles. should @ whether classes implement appropriate levels of abstraction. example, class needs access multiple data models may benefit accessing them through facade or repository.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -