I want to use strategy pattern, but I wander if it is correct to use "this pointer" with the strategy pattern interface.

This is required in order to get internal information which is required for the algorithm, but in all examples I've seen for Strategy pattern, there is no use of this pointer, so I'm not sure if this a correct thing to do.

EDIT: Why do I need this pointer parameter ? For example I have filemanager class which contain several parameters of files and folder state, and the strategy algorithm is used for decision making of files to be deleted and opened and to return current file handler. using this and getters and setters make it easy to handle the algorithm input and output.

  • Unclear what help you need. Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it’s hard to tell what problem you are trying to solve or what aspect of your approach needs to be corrected or explained. See the How to Ask page for help clarifying this question.
    – gnat
    Commented May 6, 2015 at 15:24
  • 1
    I have edited the question. I think it is more undestdood now. If not - please tell me.
    – ransh
    Commented May 6, 2015 at 17:35
  • Can you attach some example code here?
    – Dawid Pura
    Commented May 6, 2015 at 17:42
  • I don't have any code yet, just a concept.
    – ransh
    Commented May 6, 2015 at 19:06

1 Answer 1


There is no "correct" in programming. There are good things, there are bad things, but more often than not there's a series of tradeoffs that are some good and some bad. Even if you made code that did the job and mislabeled it the strategy pattern, that doesn't make the code incorrect; it just makes your communication confusing.

Rant aside, using this in the strategy pattern is perfectly fine. These are called functors in C++, and are comparable to function objects and closures in other languages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.