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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:23:27+00:00 2026-06-02T01:23:27+00:00

At run time, based on user behavior and history, I need to perform a

  • 0

At run time, based on user behavior and history, I need to perform a sorting operation. In my case, SortByDate/SortByDemand/SortByConsumption will just return the string, or we can say order by clause(which can be complex).

In most of the forums, I have found Strategy pattern should be used for sorting.

enter image description here

I have attached the image for Strategy pattern here. Util class will call the object of one the three classes i.e SortByDate/SortByDemand/SortByConsumption

So every time a new method of sorting is defined, I need to change the util class and define a new Strategy.

enter image description here

If however I implemented it using factory, the util class just need to call the factory and it will take care of which class to call. So I think I should use factory.

However I have read that strategy is best pattern for such needs. Why is strategy pattern is better here?

  • 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-02T01:23:29+00:00Added an answer on June 2, 2026 at 1:23 am

    Strategy is a pattern aimed at allowing you to add new (in your case sort) algorithms to your software without breaking the clients of the algorithms. It’s an investment in design complexity that will pay off if you need to add new algorithms without breaking your clients. Factory is a pattern that complements Strategy because the clients of the algorithm implementations should not know specifically which implementation they’re using (in terms of software classes). The factory instantiates the concrete implementations of the algorithm so the client can use them without knowing the details.

    Here’s the static structure:
    enter image description here

    Here’s the dynamic:

    enter image description here

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

Sidebar

Related Questions

I want to run a relatively time consuming script based on some form input,
we need to evaluate a value in an object in run time while we
Okay, so I need to create a 3D data-structure at run-time, I decided to
I have a Grid. The grid's columns are auto-generated at run-time based on the
I need to determine the StringFormat of some bound TextBlocks at runtime based on
I am getting this run time error when using IID_IWebBrowser2 interface of CLSID_InternetExplorer. Run-Time
Just wondering what the run time of lookup for set() is? O(1) or O(n)?
Many times i run time consuming PHP scripts that echo status updates like 'batch
The following XAML produces a run-time Binding error when I click on an item
my app has the navController and at run time I have NSString *propertyName =

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.