I actually had an interesting discussion lately with builders; so this topic interests me. Since builders are inherently mutable (and they should be right? it's a process of constructing an object), it's okay to use "set" methods. For example, see Spring's BeanDefinitionBuilder [1]. But you don't have to take this approach. It's also fine to name the mutator like an operation; see Java EE's URIBuilder [2] for that approach.
My preference comes down to whether the in-process information is retrievable? If so, I prefer getter/setter; otherwise just go with foo() over setFoo() [1] https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/support/BeanDefinitionBuilder.html [2] https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/UriBuilder.html Cheers, Paul On Mon, Nov 30, 2015 at 1:44 PM, Gary Gregory <[email protected]> wrote: > I like "set" better, but that's just because I like to type "set" and use > auto-complete. I'd rather not have to decide if I have to type "set" or > "with" and then auto-complete. > > Gary > > On Mon, Nov 30, 2015 at 11:36 AM, Matt Sicker <[email protected]> wrote: > >> Sorry, but I introduced this problem a while ago by using withFoo() in >> some builder classes, but setFoo() in other builder classes. Both are >> equally valid naming schemes for builder classes. It would be great to be >> consistent, though. Which one would be preferable? >> >> -- >> Matt Sicker <[email protected]> >> > > > > -- > E-Mail: [email protected] | [email protected] > Java Persistence with Hibernate, Second Edition > <http://www.manning.com/bauer3/> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> > Spring Batch in Action <http://www.manning.com/templier/> > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory >
