[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

C++ Delegator Design -- Please Critique & Suggest Improvements

Asked by Jonah11 in C++ Programming Language, Design Patterns, Design & Methodology

Tags: c++, ood, design, delegator

Hi,

I'm using the delegator pattern as part of the AI for a strategy game I'm writing in C++.  The details of the game are unimportant.  All you need to know is that there are various game states that come up while playing, and I need to handle each one differently.  What's more, as my code evolves, I will need to add new games states that I hadn't thought of (dealing with more and more specific cases)....

The delegator class has only two relevant methods:

void add(Condition* condition, GameState* gamestate);
Action getNextAction();

The delegator will loop through the conditions (which can be thought of as describing game states), and find a gamestate which matches the current condition.  The delegator will then delegate its "getNextAction()" to the gamestate's "getNextAction()" method.  The gamestate object will then return an action.

This part of the design I am happy with.  My problem is with the specifics of how I've handled the conditions.  I have a condition class, with a virutal "isTrue()" method.  I then subclass the Condition class to create the concrete condition classes that correspond to game states.  But these concrete condition classes only need to be created once, and also should be globally accessbile.  To answer both these requirements, I've created a convenience class call "Cond" that looks like this:

class Cond {
public:
      static ConcreteCondition1 concreteCondition1;
      static ConcreteCondition2 concreteCondition2;
      static ConcreteCondition3 concreteCondition3;
      //and so on
};

Now, the benefit of this is that I can write statements like this:

delegator_->add(&Cond::concreteCondition1, new GameStateForCondition1());

On the other hand, every time I create a new condition, I must not only create a new condition class, but also remember to add a static instance of that class to "Cond".  I'm not sure if this is bad design or not, but something about it does not sit right with me.

In addition, the condition classes themselves all simply implement the single "isTrue" method -- thus, they exist merely as a formalism for containing a function, so that I can pass object around rather than passing pointers to functions around.  This seems reasonable, but I wasn't entirely sure about that design decision either.  

I'm looking for general comments about the effectiveness of this design.  Any and all feedback will be much appreciated!
[+][-]10/02/09 02:27 AM, ID: 25476229Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C++ Programming Language, Design Patterns, Design & Methodology
Tags: c++, ood, design, delegator
Sign Up Now!
Solution Provided By: itsmeandnobodyelse
Participating Experts: 2
Solution Grade: A
 
[+][-]10/02/09 02:32 AM, ID: 25476255Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/02/09 08:44 AM, ID: 25478991Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/02/09 09:47 AM, ID: 25479618Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/02/09 10:00 AM, ID: 25479733Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/02/09 10:09 AM, ID: 25479812Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]10/02/09 11:34 PM, ID: 25484138Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/02/09 11:40 PM, ID: 25484151Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/03/09 01:17 AM, ID: 25484390Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/03/09 01:25 AM, ID: 25484410Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/03/09 04:30 AM, ID: 25484853Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625