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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:14:34+00:00 2026-05-15T00:14:34+00:00

I have some big (more than 3 fields) objects that can and should be

  • 0

I have some big (more than 3 fields) objects that can and should be immutable. Every time I run into that case I tend to create constructor abominations with long parameter lists.

It doesn’t feel right, it is hard to use, and readability suffers.

It is even worse if the fields are some sort of collection type like lists. A simple addSibling(S s) would ease the object creation so much but renders the object mutable.

What do you guys use in such cases?

I’m on Scala and Java, but I think the problem is language agnostic as long as the language is object oriented.

Solutions I can think of:

  1. “Constructor abominations with long parameter lists”
  2. The Builder Pattern
  • 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-15T00:14:34+00:00Added an answer on May 15, 2026 at 12:14 am

    Well, you want both an easier to read and immutable object once created?

    I think a fluent interface CORRECTLY DONE would help you.

    It would look like this (purely made up example):

    final Foo immutable = FooFactory.create()
        .whereRangeConstraintsAre(100,300)
        .withColor(Color.BLUE)
        .withArea(234)
        .withInterspacing(12)
        .build();
    

    I wrote “CORRECTLY DONE” in bold because most Java programmers get fluent interfaces wrong and pollute their object with the method necessary to build the object, which is of course completely wrong.

    The trick is that only the build() method actually creates a Foo (hence you Foo can be immutable).

    FooFactory.create(), whereXXX(..) and withXXX(..) all create “something else”.

    That something else may be a FooFactory, here’s one way to do it….

    You FooFactory would look like this:

    // Notice the private FooFactory constructor
    private FooFactory() {
    }
    
    public static FooFactory create() {
        return new FooFactory();
    }
    
    public FooFactory withColor( final Color col ) {
        this.color = color;
        return this;
    }
    
    public Foo build() {
        return new FooImpl( color, and, all, the, other, parameters, go, here );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 444k
  • Answers 444k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer IIRC, for such purposes hashes and strings are equivalent, so… May 15, 2026 at 6:31 pm
  • Editorial Team
    Editorial Team added an answer Are you talking about a compound key situtation? <directory> <employee>… May 15, 2026 at 6:31 pm
  • Editorial Team
    Editorial Team added an answer Paperclip uses ImageMagick under the covers, here's a link to… May 15, 2026 at 6:31 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.