[ 
https://issues.apache.org/jira/browse/LOG4J2-653?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14008595#comment-14008595
 ] 

Matt Sicker commented on LOG4J2-653:
------------------------------------

The difference in reflection code between injecting parameters versus injecting 
fields isn't that different (though we would get more immediate feedback about 
incorrect types in the field case). The advantage here is that we can 
completely replace the factory methods with the builder classes. This would 
make testing easier, and there'd be less code to maintain. Also, we can define 
default values directly in the class:

{code}
public class Foo {
    @PluginAttribute("bar")
    private int bar = 42;
}
{code}

versus

{code}
public static Foo createFoo(@PluginAttribute(value = "bar", defaultValue = 
"42") int bar) {
    // ...
}
{code}

If you've ever used {{@Inject}} from Google Guice or Spring or anything else 
that supports it, this is rather similar. It will also make it easier for 
plugin developers IMO. I'd rather write a builder class than a mega-method! :)

> Add plugin builder classes as alternative to factory methods.
> -------------------------------------------------------------
>
>                 Key: LOG4J2-653
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-653
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Core
>            Reporter: Matt Sicker
>            Assignee: Matt Sicker
>              Labels: config
>
> It would be useful to have builder-style classes as an alternative to plugin 
> factory methods. This would be useful in two settings:
> # Easier to construct plugins in tests and in the code.
> # Can add annotations to fields for value injection in the PluginBuilder 
> class.
> This could replace the existing factory methods, or it could complement it. 
> This would also make it easier to support programmatic configuration.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to