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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:13:56+00:00 2026-05-23T21:13:56+00:00

I often get into situation when I’d like to use template method pattern, but

  • 0

I often get into situation when I’d like to use template method pattern, but the template method expects a different type of a parameter, like this:

public abstract class AbstractFoo  {

    public void process(TypeA a, TypeB b) {

     //do common processing
        if (b == null) {
          doProcess(a);
        } else if(a == null) {
          doProcess(b);
        }
    }

    public abstract void doProcess(TypeA a);
    public abstract void doProcess(TypeB b);
}

This doesn’t look good. One of the supplied paramaters would have to be null and all services would have to implement dummy doProcess methods for other types. Is there any better pattern for this? How do you deal with this ? I don’t want to use constructor because these services are spring beans. Also the same problem applies to Strategy pattern.

  • 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-23T21:13:56+00:00Added an answer on May 23, 2026 at 9:13 pm
    public abstract class AbstractFoo<T>  {
    
        public void process(T a) {
    
            //do common processing
    
            doProcess(a);
        }
    
        protected abstract void doProcess(T a);
    }
    
    public class Person extends AbstractFoo<Person> {
        @Override
        protected void doProcess(Person p) {
            p.draw();
        }
    }
    
    
    public class Car extends AbstractFoo<Car> {
        @Override
        protected void doProcess(Car c) {
            c.draw();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still relatively a beginner in TDD, and I often end up into the
I am trying to catch an exception but occasionally get an inner exception. I
I think that this problem occurs often on a web application development. But I'll
I have a WinForms app that uses the Settings feature of .NET 2, but
the code below is working, but I want to make sure it's correct .
I'm a .Net developer moving from Winforms to WPF and have run into a
I have a multi-dimensional array that I am trying to feed into difflib.get_close_matches() .
I am attempting to set the Name property of a Page in the constructor:
I have two VC++ 6 apps writing/updating data in a common Access 2000 database
I'm running a distributed job on a cluster. I need to execute a script

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.