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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:57:34+00:00 2026-05-27T02:57:34+00:00

Sometimes when using the strategy pattern I find some of the algorithm implementations do

  • 0

Sometimes when using the strategy pattern I find some of the algorithm implementations do not require the same parameter list.

For example

    public interface Strategy{
     public void algorithm(int num);
    }

    public class StrategyImpl1 implements Strategy{
     public void algorithm(int num){
       //num is needed in this implementation to run algorithm
     }
    }

    public class StrategyImpl2 implements Strategy{
     public void algorithm(int num){
       //num is not needed in this implementation to run algorithm but because im using same
       strategy interface I need to pass in parameter
     }

}

Is there a different design pattern I should use ?

  • 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-27T02:57:34+00:00Added an answer on May 27, 2026 at 2:57 am

    This is generally acceptable, although if there are parameters that are only needed by some implementations, perhaps it would make more sense to provide those to the implementation’s constructor (i.e. leave them out of the strategy interface), although this may not be an option in your situation.

    Also, another option is to make a Parameters class and have your strategy method simply take one of these. This class can then have getters for various parameters (i.e. int num), and if a particular implementation doesn’t need to use num then it simply won’t call parameters.getNum(). This also gives you flexibility in adding new parameters without having to change any existing strategy implementations or interfaces.

    With that said, a class like Parameters leaves me feeling like there’s been an abstraction failure somewhere else, although sometimes you just gotta make it work.

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

Sidebar

Related Questions

Sometimes when using eclipse it loses references to the JRE. i.e. It cannot find
When using Mercurial I sometimes find that it is hard to understand the relationship
Sometimes I create some quick personal projects using C# with Windows Forms or WPF
When using powershell, sometimes I want to only display for example the name or
I have some s in my webpage, is there anything wrong with sometimes using
I'm not so experienced but i worked on some big Java EE projects (using
I'm prototyping GUI layout with PyGTK, sometimes using glade/builder sometimes not, and the following
When using irb or rails console , I sometimes get stuck. For example, I
Using ack (sometimes packaged as ack-grep) I know that I can find paths that
Sometimes I tend using autocomplete from eclipse (3.5) for anonymous inner types. For some

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.