Skip to main content
4 events
when toggle format what by license comment
Oct 25, 2021 at 14:24 comment added JimmyJames But it is possible to use static methods without tight coupling. For example a static method can be used as an implementation for a single method interface such as Comparator and passed to a e.g. a TreeSet without the TreeSet knowing anything about the static method. IIRC, the static method doesn't even need to be public.
Oct 25, 2021 at 8:42 comment added David Arno @JimmyJames, sure you can pass function references around and I've adopted using delegates rather than objects in the dependency graph before. But it needs to be done with care as it can result in far too much mocking all too easily as one can end up mocking the entire factory rather than the types it creates, which easily leads to useless tests.
Oct 22, 2021 at 16:13 comment added JimmyJames "In your first code example, you have a factory, but it is a factory with problems. It's a static method, so any code that uses this factory is tightly coupled to this one implementation." That would have been true years ago but you can pass references to static methods in Java since 1.8.
Oct 22, 2021 at 7:39 history answered David Arno CC BY-SA 4.0