R4481 Checkstyle Parameter Rename Issue
Etienne Dysli-Metref
etienne.dysli-metref at switch.ch
Tue Sep 13 06:29:36 EDT 2016
On 07/09/16 23:23, Brent Putman wrote:
>> Nothing's absolute, but that was my impression as to recommended
>> practice, and why Spring has the init-method ook.
>
> It's true that the Spring project definitely has, or at least had, that
> position. IIRC way way back they originally didn't even support ctors
> at all on wired beans, or at last poorly. But they started supporting
> non-default ctors eventually as first-class citizens. So I'm not so
> sure that's their philosophical position now.
If Spring's documentation is any indication of what they think, here
what it says in the sidebar named "Constructor-based or setter-based
DI?" [1]:
> Since you can mix constructor-based and setter-based DI, it is a good
> rule of thumb to use constructors for mandatory dependencies and
> setter methods or configuration methods for optional dependencies.
> Note that use of the @Required annotation on a setter method can be
> used to make the property a required dependency.
>
> The Spring team generally advocates constructor injection as it
> enables one to implement application components as immutable objects
> and to ensure that required dependencies are not null. Furthermore
> constructor-injected components are always returned to client
> (calling) code in a fully initialized state. As a side note, a large
> number of constructor arguments is a bad code smell, implying that
> the class likely has too many responsibilities and should be
> refactored to better address proper separation of concerns.
>
> Setter injection should primarily only be used for optional
> dependencies that can be assigned reasonable default values within
> the class. Otherwise, not-null checks must be performed everywhere
> the code uses the dependency. One benefit of setter injection is that
> setter methods make objects of that class amenable to reconfiguration
> or re-injection later. Management through JMX MBeans is therefore a
> compelling use case for setter injection.
>
> Use the DI style that makes the most sense for a particular class.
> Sometimes, when dealing with third-party classes for which you do not
> have the source, the choice is made for you. For example, if a
> third-party class does not expose any setter methods, then
> constructor injection may be the only available form of DI.
[1]
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html
"7.4.1 Dependency Injection"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://shibboleth.net/pipermail/dev/attachments/20160913/19513c53/attachment.sig>
More information about the dev
mailing list