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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:35:17+00:00 2026-05-24T21:35:17+00:00

I have the following problem illustrated by the pseudo code below (might not make

  • 0

I have the following problem illustrated by the pseudo code below (might not make a whole lot of sense):

class Form {
    boolean loggedOn = false;
    String id = null;
    ...get/set shared methods
}

class SearchFormA extends Form{
    String name = null;
    String email = null;

    ...get/set methods
}

class SearchFormB extends Form{
    String age = null;
    String gender = null;

    ...get/set methods
}

class Search {
    public Search(HttpServletRequest request){
            String searchMode = (String) request.getSearchMode();
        if("0".equals(searchMode)){
            SearchFormA formA = new SearchFormA();
            formA.setName((String)request.getParameter("name"));
            formA.setId((String)request.getParameter("id"));
            ...populate form
            request.getSession().setAttribute("formA",formA);
        }

        if("1".equals(searchMode)){
            SearchFormB formB = new SearchFormB();
            formB.setAge((String)request.getParameter("age"));
            formB.setId((String)request.getParameter("id"));
            ...populate form
            request.getSession().setAttribute("formB",formB);
        }

        ...rest of code
    }
}

What i’ve done is using reflection, but is there any other way to do it at compile time?
I’ve also tried Factory method, but the classes SearchFormA and SearchFormB does not have much in common.

EDIT: ok basically, in this case i have 4-5 searchModes, each searchMode has a different form. Between these forms they share certain similar fields. In future i might have to add 10 searchModes and it’s going to be repeating alot of populating of the same fields.

  • 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-24T21:35:18+00:00Added an answer on May 24, 2026 at 9:35 pm

    What you’re obviously trying to avoid is that in the Search method you’d have to keep appending to the if structure (spaghetti code).

    I feel like the situation you’re describing isn’t all that different from the one I wrote this answer for. That would mean that Strategy and Template (and others) could come in handy here.

    Cheers,
    Wim

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

Sidebar

Related Questions

The problem I have is illustrated in the following code. #include <iostream> #define X
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have the following problem using template instantiation [*]. file foo.h class Foo {
I have the following problem: I have a form in site/banen (currently local running
Is there a solution to the problem illustrated in the code below? Start by
My problem can be illustrated in the following example code, which sets up a
I have following problem: I have built a tabbar application with 4 tabs. I
I have the following problem: I have an HTML textbox ( <input type=text> )
I have the following problem using subversion: I'm currently working on the trunk of
I have the following problem in my Data Structures and Problem Solving using Java

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.