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 3670074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:19:12+00:00 2026-05-19T02:19:12+00:00

When creating classes for immutable objects immutable meaning that state of instances can not

  • 0

When creating classes for “immutable objects” immutable meaning that state of instances can not be changed; all fields assigned in constructor) in Java (and similar languages), it is sometimes useful to still allow creation of modified instances. That is, using an instance as base, and creating a new instance that differs by just one property value; other values coming from the base instance. To give a simple example, one could have class like:

public class Circle {
  final double x, y; // location
  final double radius;

  public Circle(double x, double y, double r) {
    this.x = x;
    this.y = y;
    this.r = r;
  }

  // method for creating a new instance, moved in x-axis by specified amount
  public Circle withOffset(double deltaX) {
    return new Circle(x+deltaX, y, radius);
  }
}

So: what should method “withOffset” be called? (note: NOT what its name ought to be — but what is this class of methods called).
Technically it is kind of a factory method, but somehow that does not seem quite right to me, since often factories are just given basic properties (and are either static methods, or are not members of the result type but factory type).

So I am guessing there should be a better term for such methods. Since these methods can be used to implement “fluent interface“, maybe they could be “fluent factory methods”?
Better suggestions?

EDIT: as suggested by one of answers, java.math.BigDecimal is a good example with its ‘add’, ‘subtract’ (etc) methods.

Also: I noticed that there’s this question (by Jon Skeet no less) that is sort of related (although it asks about specific name for method)

EDIT, MAY-2014: My current favorite is mutant factory, FWIW.

  • 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-05-19T02:19:13+00:00Added an answer on May 19, 2026 at 2:19 am

    I call those types of methods “copy methods”.

    While the clone() method creates an exact copy, a copy method makes a copy of an instance, usually with an implied or explicit variation. For example, String#toUpperCase() would be a copy method of the immutable String class – it copies an instance with a variation: it upcases all the letters.

    I would consider withOffset() method in your example to be a similar copy method.

    I don’t know of any references that document the term “copy method”. I’m borrowing the term “copy” from its use in C++: copy constructors and the “copy” naming guideline from the Taligent Coding Standards (more info).


    As for the term “fluent factory methods”, I don’t know why “fluent” would make a difference, since a “fluent interface” is just an API style (separate from the builder pattern). If the term “factory method” doesn’t apply here, I don’t see how calling it a “fluent factory method” makes it apply any better.

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

Sidebar

Related Questions

I have some classes that represent immutable objects (Quantity, Price, Probability). Is there some
What is the best way to go about creating javascript classes so that objects
While creating classes in Java I often find myself creating instance-level collections that I
I'm creating a simple API that creates typed classes based on JSON data that
I've been creating snapins with the new MMC 3.0 classes and C#. I can't
All of the collection classes have two versions - mutable and immutable, such as
I am dynamically creating classes which contain spring beans, however the beans are not
Ever since I started using .NET, I've just been creating Helper classes or Partial
What is best practice when creating your exception classes in a .NET solution: To
I frequently find myself creating classes which use this form (A): abstract class Animal

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.