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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:08:01+00:00 2026-05-23T15:08:01+00:00

I am programming in Java but this is a more of a design question

  • 0

I am programming in Java but this is a more of a design question so any OO programmer could probably answer this question. I have a question concerning the Strategy design pattern. Here are several inks I have found useful:

  1. Strategy Pattern Explained-OO Design.

I am using the strategy pattern twice with one group of four strategies and one group of three. In each case I am deciding which strategy to use by maintaining a decaying counter. if the strategy the software decides to use is successful then the counter is incremented by one. If the strategy used is not successful then the counter is decremented by one. Regardless of success or failure ALL counters are multiplied by a number around .9 to “decay” the counters over time. The software will choose which strategy to use based on which strategy has the highest counter. An example of my very simple UML is shown below:

Example UML.

And in Link form (for easier reading):
Example UML

The UML above is the mockup I would like to use. If you can’t tell from the above UML, I am writing a Rock, Paper, Scissors game with the intention of beating all of my friends.

Now, on to the problem:

I cannot decide how to implement the “counter system” for deciding which strategy to use. I was thinking about some kind of “data” class where all counters and history strings could be stored, but that just seemed clunky to me. At all times I am maintaining about 2 strings and about eight counters (maybe more maybe less). That is why I was thinking about a “data” class where everything could be stored. I could just instantiate the class to be used in the chooseStrategy() and chooseMetaStrategy() methods, but I just don’t know. This is my first project that I will be working on my own for and I just cannot decide on anything. I feel like there is definitely a better solution but I am not experienced enough to know.

Thanks!

————————————follow-up 1——————————————–

Thank you so very much on everyone’s answers and kind words. I do have a few follow up questions though. I am new to StackOverflow (and loving it) so if this is not the correct place for a followup question please let me know. I am editing my original post because my follow-up is a little lengthy.

I was looking into Paul Sonier’s advice about using the composite pattern and it looked very interesting (thanks Paul!). For the purpose of the HistoryMatching and “intelligent” AntiRotation strategies I want to implement a string of all opponent plays accessible to both classes. Also, I want the history string to be edited no matter what strategy my program played so that I can keep an accurate record of the opponent’s plays. The more comprehensive the string (actually I will probably use a LinkedList but if anyone knows of a better (sub-String/sub-List) search method/collection please let me know) the better the strategy can predict the opponent’s behavior.

I was wondering how I could implement this “string” or collection while still using the composite pattern.

Also, TheCapn brought up that it would be a good idea to store different counters and history collections for each opponent. Any thought on how to implement this with the composite pattern?

  • 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-23T15:08:01+00:00Added an answer on May 23, 2026 at 3:08 pm

    Ideally, the intent is to have the counters be associated with the strategies, because they’re counting the successes of the strategies. However, you don’t necessarily want the strategies to know anything about the fact that they’re being counted. To me, this indicates a Composite pattern, whereby you wrap your Strategy class in a class which has logic for tracking / degrading / modifying the count of usages.

    This gives you locality (the count is stored with the strategy it’s counting) and functional composition (count functionality is encapsulated in the composition class). As well, it maintains the isolation of the strategy class from other influences.

    Your design breakdown so far looks good; you’re certainly on a good and interesting path. Hope this helps!

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

Sidebar

Related Questions

Okay this is probably a rookie question, but I have never done GUI programming
This is more of a language design rather than a programming question. The following
I'e been programming Java forever, but have been away from it for a while.
I have been programming in Java since 2004, mostly enterprise and web applications. But
I have done Java and JSP programming in the past, but I am new
Have you ever thought about the implications of this change in the Java Programming
So I am primarily a C# and Java developer but I suppose this question
I'm pretty new to Perl but have been programming in java for several months
I've just started programming with Java, so might appear as silly question, but I
So this may seem like a general question..but for learning a programming language quickly

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.