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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:50:40+00:00 2026-06-18T04:50:40+00:00

Please deal with this basic question. I have an abstract class C1 which extends

  • 0

Please deal with this basic question.

I have an abstract class C1 which extends another abstract class C0 and is extended by multiple sub-classes (C21 and C22).

@Component
public abstract class C0 {
    protected abstract String getCaller();  
//Some other methods.
}

.

public abstract class C1 extends C0 {
//Set of methods which are used by children and then calls methods of C0 which then use getCaller();
}

.

    @Controller
    public class C21 extends C1 {

    @RequestMapping(value = "abc", method = RequestMethod.GET)
    public String start(@RequestParam(value = "kw", required = true) String p1,
            @RequestParam(value = Constant.REQUEST_PARAM_KEYWORDID, required = true) long p2) throws Exception {
//Some processing and calls controllers defined in abstract class C1
        return "200";
    }


    @Override
    protected String getCaller() {
        return "C21";
    }

}

.

@Controller
public class C22 extends C1 {

    @RequestMapping(value = "abc", method = RequestMethod.GET)
    public String start(@RequestParam(value = "kw", required = true) String p1,
            @RequestParam(value = Constant.REQUEST_PARAM_KEYWORDID, required = true) long p2) throws Exception {
//Some processing and calls controllers defined in abstract class C1
        return "200";
    }


    @Override
    protected String getCaller() {
        return "C22";
    }

}

C0 contains an abstract method getCaller(); Callers of C21 and C22 are different but they can be identified by the parameter passed to only method start(p1,p2) of these classes.

start(p1,p2) does similar thing in both the classes. Only difference in C21 and C22 is the implementation of getCaller() which is fixed and can anyways be extracted from parameters of start. So, I decided to create single class instead of C21 and C22.

I cannot create setCaller() so, I wanted to create a final method and a private variable caller in abstract class C1 which could be populated with the parameters of start method and returned in getCaller() (which is called from abstract class C0).

Is this the correct approach? Is there any better way or pattern for this?

  • 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-18T04:50:41+00:00Added an answer on June 18, 2026 at 4:50 am

    Only difference in C21 and C22 is the implementation of getCaller() which is fixed and can anyways be extracted from parameters of start.

    Since you have to change only a single method, you will be better off with a single non-abstract implementation C1 instead of an abstract C1 and a pair of C21 and C22. You can do something like this:

    Caller caller;
    public start(SomeType1 p1, SomeType2 p2, SomeType3 p3) {
        caller = new Caller(p1, p2, p3);
        ...
        // Do other stuff
    }
    
    public Caller getCaller() {
        return caller;
    }
    

    In case there are other classes in addition to C21 and C22 inheriting C1, you may want to keep your C1 abstract, and add a non-abstract C2 with an above implementation.

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

Sidebar

Related Questions

Please deal with this trivial question. I am getting some URLs like SOME_DOMAIN?q\x3dnintendo+mathe\x26um\x3d1\x26ie\x3dUTF-8\x26tbm\x3dshop\x26cid\x3d8123694338777545283\x26sa\x3dX\x26ei\x3dL8cjUJmHO8L30gGa1ICgCw\x26ved\x3d0CI4BEIIIMAk which
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
I have a python client which pushes a great deal of data through the
I have a very amateurish question, so please don't bomb me. I work in
I have an error which says expected an indented block Could you please guide
Deal all, I have implemented some functions and like to ask some basic thing
I have a question how to deal with a saga where the decision making
This has to be a common question that all programmers have from time to
I can't deal with this. Please help me. This is array: $arr = array(data
This is a trivial question but I am quite new to this and please

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.