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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:06:35+00:00 2026-05-29T06:06:35+00:00

Note: I’ve read this and its not quite what I’m looking for: I have

  • 0

Note: I’ve read this and its not quite what I’m looking for:

I have an app that builds up XML from an input file and creates one of two outputs, depending upon the file chosen. It was a “quick n dirty” app to get round an immediate problem, but I know it’s going to find further use and want to pre-empt this by refactoring.

At the moment I have a “builder” class that takes the input (in its ctor) and exposes a property which is the required XElement. However, many of the XElements are identical, except for the content, for both of my XML outputs. (Oh, please ignore the validation part which I’ll refactor separately)

So I’m looking at a sensible way of DRYing my app:

At the moment I have something like this.

public FirstBuilder(string line, int lineNumber, bool output, string subjectType, string inquiryCode)
{
    var split = Regex.Split(line, @"\|");
    if (split.Count() != SPLIT_COUNT)
        throw new Exception("This does not appear to be a valid First Type input file.");

    _lineNumber = lineNumber;
    _reportId = output ? TXT_REPORT_ID : XML_REPORT_ID;
    _subjectType = subjectType;
    _responseType = output ? TXT_RESPONSE_TYPE : XML_REPONSE_TYPE;
    _inquiryCode = inquiryCode;

    _product = split[0];
    _number = split[1];
    _amount = split[2];
    _currency = split[3];
    _name = split[4];
    _nationalId = split[5];
    _gender = split[6];
    _dateOfBirth = split[7];
    _nationality = split[8];
}

public XElement RequestElement
{
    get
    {
        return new XElement("REQUEST",
            new XAttribute("REQUEST_ID", _lineNumber),
            RequestParametersElement,
            SearchParametersElement);
    }
}

private XElement RequestParametersElement
{
    get
    {
        return new XElement("REQUEST_PARAMETERS",
            ReportParametersElement,
            InquiryPurposeElement,
            ApplicationElement);
    }
}

private XElement ReportParametersElement
{
    get
    {
        return new XElement("REPORT_PARAMETERS",
            new XAttribute("REPORT_ID", _reportId),
            new XAttribute("SUBJECT_TYPE", _subjectType),
            new XAttribute("RESPONSE_TYPE", _responseType));
    }
}

etc. etc...

//used by
var x = new FirstBuilder(x,y,z,etc.).RequestElement();

This all works and is very fast…but SecondBuilder also uses these same elements, along with some different ones.

So I’m looking at the “best” way to refactor these out:
Shared Abstract class with inheritance?
Shared “Helper” classes?
Extension methods to return “built” elements?
Classes per element that extend XElement?

My suspicion is that this will balloon from the two examples as a quick solution to around 30 in then next month!

THX.

  • 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-29T06:06:36+00:00Added an answer on May 29, 2026 at 6:06 am

    I would refactor the private properties to methods that receive the required values as input parameters. You can then move them into a PartsBuilder class and use that one in you concrete builders.

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

Sidebar

Related Questions

(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
Note that this relates to focus and blur events on a window, not on
Note: I have seen this and tried to take as much from it as
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note that I am not asking which to choose (MVC or MVP), but rather
Note This is not a REBOL-specific question. You can answer it in any language.
Note the tag: VBA , not VB6, not VB.NET. This is specific to VBA
NOTE: If you don't want to read this, check TLDR version at bottom of
NOTE: This question is only loosely related to tinyxml, however including details like that
Note: I have a workaround to this problem, but I'd prefer to comma-separate the

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.