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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:47:08+00:00 2026-06-14T19:47:08+00:00

I have three types of algorithms, each take a different parameter type needed for

  • 0

I have three types of algorithms, each take a different parameter type needed for prcoessing.

class AlgorithmA
{
    Execute(int param);
}

class AlgorithmB
{
    Execute(string param);
}

class AlgorithmC
{
    Execute();
}

to employ the strategy pattern with MEF, I did the following:

interface IAlgorithm
{
    int IntegerParam{get;set;}
    string StringParam{get;set;}
    string AlgorithmName {get;}
    void Execute();
}

and in the client:

[ImportMany]
IEnumerable<IAlgorithm> Algorithms { get; set; }

IAlgorithm algorithm=Algorithms.Single(a => a.AlgorithmName == name);
algorithm.IntegerParam=integerParam;
algorithm.StringParam=stringParam;
algorithm.Execute();

now the question is, it’s obviously wrong to supply necessary parameters as properties, but on the other hand, if i supply them as constructor parameters, it will defeat the very purpose of the pattern.
what would you do ?

  • 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-14T19:47:09+00:00Added an answer on June 14, 2026 at 7:47 pm

    The strategy pattern should pass the same parameters to its strategies, regardless of the one that was actually chosen; then, each strategy should decide what to do with these parameters.

    In case you need to pass two parameters, you should probably define something like this:

    interface IAlgorithm
    {
        string AlgorithmName {get;}
        void Execute(string paramA, int paramB);
    }
    
    algorithm.Execute(stringParam, intParam);
    

    Then if a certain strategy only needs to use the first parameter, then it simply uses it and ignores the other parameter.

    What I think you’re missing is that if you try to pass different parameters to different strategies then you’re pretty much giving up on the strategy here, because you already know something about the strategy being used, how it works internally and what it needs.

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

Sidebar

Related Questions

I have a rails application that has three different types of users and I
Please consider the following three .NET types: I have an interface, an abstract class,
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have three types of products - Retail products (ID,product_categoryId,price,name) - Courses (ID,course_categoryId,price,name,roomId) -
I have three fixed width integer types: typedef int16_t TABCellManagedDataKey; typedef int16_t TABCellManagedDataIndex; typedef
Work on asp.net vs05. I have three type of value Like:IsDesign,IsPrinting,IsInstall they are bit
I have a list of elements, each one identified with a type, I need
I have tried different types of Password Strength Meters or Password checkers, but all
Basically I have a list of objects where each object might implement a different
I have read a document that they say: In java there two types of

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.