Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:06:42+00:00 2026-06-11T16:06:42+00:00

I saw somewhere on SO today a design pattern that was used to illustrate

  • 0

I saw somewhere on SO today a design pattern that was used to illustrate a point about immutable objects in Java. The idea is to allow the user to set the value for whatever properties he wants during construction, and it looks something like this:

MyObject obj = new MyObject().name("Foo")
                             .height(5)
                             .width(3)
                             .color("blue")
                             .age(7);

Is there a name for this pattern?

In C++ I know you can just return a pointer to this in each function. How is it done the same way in Java?

For immutable objects, do you have to make a new copy of the object for each property you want to set?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:06:43+00:00Added an answer on June 11, 2026 at 4:06 pm

    If you want to construct an immutable object with approximately this style, you likely want the Builder pattern.

    The chaining visible in this is also known as a Fluent interface and is indeed enabled by returning this.

    With your code using the fluent interface on the actual object under construction, the object won’t be immutable if all the methods setting things are in fact mutators. If these methods all return a new object instead of this it could be immutable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I'm self-learning about bitwise, and I saw somewhere in the internet that arithmetic
xml.etree.ElementTree.parse is choking on my xhtml file. I saw somewhere that lxml can handle
I saw somewhere someone talking about FileReader in JavaScript. What is it? What could
I saw System.gc() somewhere on the internet today and I wanted to know if
I saw somewhere assert used with a message in the following way: assert((message, condition));
there's this problem about line crossings I saw somewhere and was trying to solve.
I saw somewhere that if we have a one-to-one function from sets X to
I saw somewhere that the style -webkit-text-stroke is not supported by any version of
I saw somewhere what seemed to be nested selects, one master select on the
I'm pretty sure I saw somewhere in a popular Git project the branches had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.