Naive question: what is the value of adding views/...
# tornadofx
w
Naive question: what is the value of adding views/fragments to a view using find() dependency injection and params VS calling a constructor and passing args into it? I can see that allowed views to be reused, but if the views are cheap to create, are there any other benefits?
t
Generally there are design benefits in leveraging dependency injection. Simplifies code a lot and makes it easy to refactor
w
I agree, but in kotlin, I tend to just use constructor injection, and use default values so that I only need to specify the args in test (and supply mocks/lambdas)
Like this: https://github.com/wakingrufus/writing-testable-functional-kotlin/blob/master/src/main/kotlin/com/grubhub/kotlin/FizzBuzzRunnerOop.kt except the default value of the line printer argument would be
System.out::println
e
@wakingrufus When the framework instantiates and locates fragments and views, those views also enter into the life cycle, so if you instantiate them manually, certain life cycle functions will not be called. Using
inject()
or
find()
will also make sure those ui components enter into the correct scope, which is cruicial for MDI style applications, or where you use anything but the default scope.
👍 1
w
Ok thanks!