E11043: method uses too many distinct injected types - extract to a dedicated component
What went wrong
A single callable (method, operator, function, service operation, program) uses more than 4 distinct injected component types via method-local injection. This makes it difficult to understand and test - it has too many collaborators.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 1304 (How do I fix E11043 when a method injects too many distin...)
How to fix it
- Extract the method into a dedicated component with field injection
- Group related injected types into a facade component
- Split the method into smaller methods with fewer dependencies
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E11043: method uses too many distinct injected types - extract to a dedicated component
#!ek9 defines module error.e11043.bad defines function orchestrate() <- rtn as Boolean? a as ServiceA! b as ServiceB! c as ServiceC! d as ServiceD! e as ServiceE! rtn: a.doA() and b.doB() and c.doC() and d.doD() and e.doE() defines component ServiceA as abstract doA() as abstract <- rtn as Boolean? default operator ? ServiceB as abstract doB() as abstract <- rtn as Boolean? default operator ? ServiceC as abstract doC() as abstract <- rtn as Boolean? default operator ? ServiceD as abstract doD() as abstract <- rtn as Boolean? default operator ? ServiceE as abstract doE() as abstract <- rtn as Boolean? default operator ?
Fixed: Let one injected facade coordinate the services
#!ek9 defines module error.e11043.good defines function orchestrate() <- rtn as Boolean? a as ServiceA! b as ServiceB! c as ServiceC! rest as Coordinator! rtn: a.doA() and b.doB() and c.doC() and rest.coordinate() defines component ServiceA as abstract doA() as abstract <- rtn as Boolean? default operator ? ServiceB as abstract doB() as abstract <- rtn as Boolean? default operator ? ServiceC as abstract doC() as abstract <- rtn as Boolean? default operator ? Coordinator as abstract coordinate() as abstract <- rtn as Boolean? default operator ?
Found a problem?
If EK9 reported E11043 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.