software design - Dependency injection OR configuration object? -


i have following constructor class

 public myclass(file f1, file f2, file f3, class1 c1, class2 c2, class3 c3) { .......... } 

as can seen, has 6 parameters. on seeing code, 1 of seniors said instead of passing 6 parameters should rather pass configuration object.

i wrote code way because have read "dependency injection", says "classes must ask want". think passing configuration object against principle.

is interpretation of "dependency injection" correct? or should take senior's advice?

"configuration object" obtuse term apply in situation; frames efforts in purely mechanical sense. goal communicate intent class's consumer; let's refactor toward that.

methods or constructors numerous parameters indicate loose relationship between them. consumer has make more inferences understand api. special these 3 files these 3 classes? information not being communicated.

this opportunity create more meaningful , intention-revealing interface extracting explicit concept implicit one. example, if 3 files related because of user, userfileset parameter express that. perhaps f1 related c1, f2 c2, , f3 c3. declaring associations independent classes halve parameter count , increase amount of information can derived api.

ultimately, refactoring highly dependent on problem domain. don't assume should create single object fulfill parameter list; try refactor along contours of relationships between parameters. yield code reflects problem solves more language used solve it.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -