I started working on a project and I saw some methods with this With
prefix and I'm wondering if this refers to a known pattern.
Does anyone know of this naming pattern?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityI've seen a with
prefix used in a couple of different ways that may be similar to what's being done in the codebase you're working on.
var myobj = MyObj.builder()
.withProperty1("property 1 value")
.withProperty2("property 2 value")
.build();
var myImmutableObj = new MyImmutableObj("property 1 value", "property 2 value");
var myImmutableObjClone = myImmutableObj.withProperty1("different property 1 value");
void
and simply set fields (essentially setters); and B) methods that set fields and returnsthis
.