Hi, I have a question related to FSM design which uses commands as well. Please guide.
What is the Best way to couple data among FSM design pattern objects (Session, State, ReportGeneration objects.)-
I have a class called StateEngine which get a request to permorm some action
to permorm that action it creates a session class object and sets up the context
for States and Commands objects.
Here each State runs one or more commands and generate result for that perticular state.
That State object saves thaose result in the Session class object(Context).
Which is later on used to generate report.
I have question what could be the best way to couple data between Session(Context), State and the reportGeneration Logic?
Few thoughts comming to me are-
1)- Pass a long list of data structures class Session data(lists..., maps...) to ReportGeneration class object by reference
(long list to parameters sharing).
2)- Declare class ReportGeneration friend to class Session so that it can have access to all it
data structures(request, each command procession results) to generate detailed report.
friend is a bit violation to encapsulation(but seems to me a bit good choice).
3)- By using accessors in Session class and passing Session reference or pointer to ReportGeneration class.
(which need too many accessors and may tend to make class huge and complex.).
below is the code to give some idea what I want to achieve.
Note: I made State friend to Session class is there any better way I can achieve encapsulation.
Please Suggest.
class SateEngine
{
public:
// It creates a new session for each action to be performed.
// here each action can have n(1...n) States and each State can have n Commands(1...n).
startState(string action );
};
class Session
{
public:
Session(string action);
// from action deduce all States and excute the one by one end state is NULL.
Request* decodeRequest(string request);
void startStateExecution();
// Transition to nextState if present else return NULL.
State* nextState();
void logResponse();
private:
string request;
Request DecodedReq;
map<string, string> resMap; // specific value used for reportGeneration
map<string, Command> commandsData;
list<Result*> sessionResult;
list<Command*> sessionCommands; // for debugging purpose reportGeneration
list<States*> sessionStates; // for debugging purpose reportGeneration
friend State; //// State class is friend to Session(Context) so it can update session private data.
friend Summary;
};
class State
{
public:
Sate(Session *session)
addCommands();
processionCommandResult();
saveToSession(); // saves values to sessions private data.
State* nextState();
void generateReport( Session *session); // if next state is NULL;
};
class Command
{
public:
void executeCommand;
void prepareResult();
private:
list<CommandResp> result;
};
class Summary
{
// uses all data structures save in Session generate summary
void prepareResponse( string& response) = 0;
};
class FinalresultSummary: public Summary
{ };
class FinalDetailedresultSummary: public Summary
{ };
↧