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

  • Home
  • SEARCH
  • 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 7778935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:31:25+00:00 2026-06-01T18:31:25+00:00

I am currently using the Builder pattern, following closely the Java implementation suggested in

  • 0

I am currently using the Builder pattern, following closely the Java implementation suggested in the Wikipedia article Builder pattern http://en.wikipedia.org/wiki/Builder_pattern

This is a sample code that ilustrates my implementation

public class MyPrimitiveObject {
  private String identifier="unknown";
  public static class Builder {
    private final MyPrimitiveObject obj = new MyPrimitiveObject();
    public MyPrimitiveObject build() { return obj; }
    public Builder setidentifier (String val) {
     obj.identifier = val;
     return this;
    }
  }
  public static Builder createBuilder() { return new Builder(); }
  @Override public String toString() { return "ID: "+identifier; }
}

In some of my applications that use this class, I happen to find very similar building code , so I thought to subclass MyPrimitiveObject in MySophisticatedObject and move all my repeated code into its constructor.. and here is the problem.

How may I invoke the superclass Builder and assign its returned object as my instance?

public class MySophisticatedObject extends MyPrimitiveObject {
  private String description;
  public MySophisticatedObject (String someDescription) {
    // this should be the returned object from build() !!
    Builder().setidentifier(generateUUID()).build()
    description = someDescription;
  }     
}
  • 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-01T18:31:26+00:00Added an answer on June 1, 2026 at 6:31 pm

    You might want to consider having a nested MySophisticatedObject.Builder which extends MyPrimitiveObject.Builder, and overrides its build() method. Have a protected constructor in the builder to accept the instance on which to set values:

    public class MyPrimitiveObject {
      private String identifier="unknown";
      public static class Builder {
        private final MyPrimitiveObject obj;
        public MyPrimitiveObject build() { return obj; }
        public Builder setidentifier (String val) {
         obj.identifier = val;
         return this;
        }
    
        public Builder() {
            this(new MyPrimitiveObject());
        }
    
        public Builder(MyPrimitiveObject obj) {
            this.obj = obj;
        }
      }
      ...
    }
    
    public class MySophisticatedObject extends MyPrimitiveObject {
      private String description;
    
      public static class Builder extends MyPrimitiveObject.Builder {
        private final MySophisticatedObject obj;
        public Builder() {
          this(new MySophisticatedObject());
          super.setIdentifier(generateUUID());
        }     
        public Builder(MySophisticatedObject obj) {
          super(obj);
          this.obj = obj;
        }
    
        public MySophisticatedObject build() {
          return obj;
        }
    
        // Add code to set the description etc.
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I'm trying to develop a rich internet application using Flash Builder 4 Beta
I am currently using the following command to upload my site content: scp -r
I'm attempting to create a class with many parameters, using a Builder pattern rather
I'm attempting to implement a MVP pattern in my latest project. Currently using the
I have an HtmlHelper extension that currently returns a string using a string builder
I'm currently using the Nokogiri::XML::Builder class to construct an XML document, then calling .to_xml
I am new Web App development using Flex Builder 3 and currently I am
I am currently using Flex (Flash Builder 4) and making web service connections to
I am currently using the latest verion of Adobe Flash Builder to create a
Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I

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.