Java – policy design pattern – select policies and counters

I'm programming in Java, but this is a more design question, so any OO programmer can answer this question I have a question about strategic design pattern Here are some inks I find useful:

> @L_ 419_ 1@.

I am using the strategy model twice, a group of four strategies and a group of three In each case, I decide which strategy to use to maintain a rotten counter If the software decides that the strategy used is successful, the counter is incremented by one If the policy used is unsuccessful, the counter is decremented by 1 Regardless of success or failure, all counters are multiplied by the decay counter by a multiple of. 9 The software will choose which policy to use according to which policy has the highest counter An example of my very simple UML is as follows:

.

And link form (easier to read): example UML

The above UML is the model I want to use If you can't learn from the above UML, I'm writing a rock, paper and scissors game to beat all my friends

Here's the question:

I can't decide how to implement "Counteraction" to decide which strategy to use I'm thinking about some "data" classes that can store all counters and historical strings, but they seem cumbersome to me At any time, I keep about 2 strings and about 8 counters (maybe less) That's why I'm considering a "data" class that can store all content I can use selectstrategy () and choosemetastrategy () methods in instantiated classes, but I just don't know This is my first project, I will work on my own, I just can't decide what I think there is a better solution, but I don't have enough experience to know

thank you!

————————————Follow up 1 -----------------

Thank you very much for your answers and kind words I do have some follow-up questions I am new to stackoverflow (and love it), so if this is not the right place for follow-up questions, please let me know I'm editing my original post because my follow-up is a little long

I'm studying Paul sonier's advice on using composite patterns. It looks very interesting (thank you, Paul!) For the purpose of "history matching" and "intelligent" reversal strategy, I want to realize the roles of all opponents in both categories In addition, regardless of the strategy of my program, I want to be able to edit the historical string so that I can accurately record each other's drama The more comprehensive the string (in fact, I may use LinkedList, but if anyone knows a better (sub string / sub list) search method / set, please let me know) strategy can better predict the opponent's behavior

I want to know how to implement this "string" or collection while still using composite patterns

In addition, the CAPN suggests that it is a good idea to store different counters and history for each opponent Any ideas on how to do this with composite patterns?

Solution

Ideally, the intent is to associate counters with the policy because they are counting the success of the policy However, you do not necessarily want these strategies to understand the facts about counting To me, this represents a composite pattern. You can include the strategy class in a class with logic to track / downgrade / modify the number of usages

This gives you location (counting storage and calculation strategy) and function combination (counting function is encapsulated in combination class) Similarly, it keeps the strategic category isolated from other impacts

Your design details look good so far; You are certainly an interesting path I hope this can help!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>