Skip to main content
6 events
when toggle format what by license comment
Sep 6, 2022 at 13:53 comment added Laiv When I should let the client define (by injection directly) the final behaviour of Base when the consumer can change the behaviour dynamically at will. If the behaviour is rarely or never altered in runtime due to a consumer choice, why should it be dynamic at all?
Sep 6, 2022 at 10:53 answer added Ewan timeline score: 2
Sep 6, 2022 at 7:05 answer added Ben Cottrell timeline score: 1
Sep 6, 2022 at 5:33 review Close votes
Sep 21, 2022 at 3:04
Sep 6, 2022 at 4:46 comment added Filip Milovanović Your "Direct Injection Construction" is just what we call dependency injection. In this case, you're injecting a function, which can be seen as an object with a single method (which is quite literal in Java). Note that Consumer<T> is an interface, which the class generated from your lambda implements. This can be generalized further - you can accept an interface or a base class, and let the client decide which implementation of the interface / base class to inject (so, the two approaches can be combined). Many (most?) design patterns work exactly that way.
Sep 6, 2022 at 0:29 history asked Robin Kreuzer CC BY-SA 4.0