inject dependencies methods constructor?


dependency injection seems good thing. general, should dependencies injected during methods need them, should injected contructor class?



see samples next denote twin ways inject same dependency.



//inject dependency methods need importantclass
class something {

open something()
{
//empty
}

open vacant a()
{
//do something but x
}

open vacant b(importantclass x)
{
//do something x
}

open vacant c(importantclass x)
{
//do something x
}
}

//inject dependency constructor once
class something {
private importantclass _x
open something(importantclass x)
{
this._x = x;
}

open vacant a()
{
//do something but x
}

open vacant b()
{
//do something this._x
}

open vacant c()
{
//do something this._x
}

}


Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?