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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:14:36+00:00 2026-05-29T21:14:36+00:00

In the strategy pattern is it ok to only do some of the logic

  • 0

In the strategy pattern is it ok to only do some of the logic in the strategy and skill keep some on my own code, will it still be the strategy pattern?

Example: i use the strategy pattern to influence how elements are ordered in my Doubly linked list.
What i have done is simply to make the strategy pattern indicated if it wish to be inserted after a given element, and then loop all elements though, and then insert the new element before the element that made the strategy pattern send false back.

Or must all sorting be done in the strategy patter for it to be a “PURE” strategy pattern?

public interface IInsertStrategy<T> {
public boolean insertAfter(T insertValue, T testValue);
}

And the add code

public void add(T value)
{
    DoublyLinkedNode<T> workingNode = head;

    // Loop though nodes, to and with the tail
    while(workingNode.next != null)
    {
        workingNode = workingNode.next;
        /* Keep going until the strategy is not true any more
         * or until we have the last node. */
        if(workingNode.next == null ||
            !insertStrategy.insertAfter(value, workingNode.value))
        {
            workingNode.previous.append(value);
            break;
        }
    }
}
  • 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-29T21:14:38+00:00Added an answer on May 29, 2026 at 9:14 pm

    It’s cleaner to have your strategy algorithm in the implementation of IInsertStrategy. Imagine if you come up with a 3rd algorithm, but can’t do it correctly because of some conflict in the add function. You end up touching two parts of your code which defeats the purpose of abstracting the insert algorithm in the first place.

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

Sidebar

Related Questions

When implementing the Strategy Pattern, where does one put the code that determines which
I am implementing a few strategies (Strategy Pattern) which have some common behavior and
When would the Strategy Pattern be used? I see client code snippets like this:
In the 2009 Wikipedia entry for the Strategy Pattern, there's a example written in
Is the Strategy Pattern based largely on the fact that there will be change
I've been doing some reading on the Strategy Pattern, and have a question. I
I have the following Strategy Pattern implemented: public abstract class RetrievalStrategy { public abstract
My question is I wanna apply strategy pattern to save log from Image above
What strategy should I use if I have an implementation of std::fstream with 32-bit
What's the best strategy to use when writing JMeters tests against a web application

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.