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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:58:09+00:00 2026-05-14T16:58:09+00:00

At the moment I have this code (and I don’t like it): private RenderedImage

  • 0

At the moment I have this code (and I don’t like it):

private RenderedImage getChartImage (GanttChartModel model, String title,
                                     Integer width, Integer height,
                                     String xAxisLabel, String yAxisLabel,
                                     Boolean showLegend) {
    if (title == null) {
        title = "";
    }
    if (xAxisLabel == null) {
        xAxisLabel = "";
    }
    if (yAxisLabel == null) {
        yAxisLabel = "";
    }
    if (showLegend == null) {
        showLegend = true;
    }
    if (width == null) {
        width = DEFAULT_WIDTH;
    }
    if (height == null) {
        height = DEFAULT_HEIGHT;
    }
    ...
}

How can I improve it?

I have some thoughts about introducing an object which will contain all these parameters as fields and then, maybe, it’ll be possible to apply builder pattern. But still don’t have clear vision how to implement that and I’m not sure that it’s worth to be done. Any other ideas?

  • 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-14T16:58:10+00:00Added an answer on May 14, 2026 at 4:58 pm

    So many parameters to a method is definitely a code smell. I would say a Chart object is waiting to be born. Here is a basic outline:

     private RenderImage getChartImage(Chart chart) { 
         //etc.
     }
     private static class Chart {
          private GanttChartModel model;
          private String title = "";
          //etc, initializing each field with its default value.
          private static class Builder {
               private Chart chart;
               public Builder(GanttChartModel model) {
                    chart = new Chart();
                    chart.model = model;
               }
               public setTitle(String title) {
                    if (title != null) {
                        chart.title = title;
                    }
               }
          }
      }
    

    Other options include using primitives on the methods instead of objects to indicate that null isn’t allowed, although that doesn’t necessarily make it better. Another option is a bunch of overloaded methods, but given the types of parameters here, that doesn’t really work because I get the idea that you want to make any of the parameters optional rather than having the first ones required and subsequent ones optional.

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

Sidebar

Related Questions

I have a sectioned UITableView using dictionaries adapting code from a tutorial (I don't
This seems to be defeating me at the moment but I don't think I
I feel like this will end in a facepalm moment but I've been banging
At the moment I have setup a custom ok cancel dialog with a drop
At the moment I have a set of divs, generated dynamically by php and
Working on a project at the moment and we have to implement soft deletion
I have a self built JSP webapp and at the moment I'm using tomcats
I have a list view control which at the moment only allows one item
I have a weird error in my C++ classes at the moment. I have
I have a Java client that calls a web service at the moment using

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.