ambuli
asked on
Constructing an object with three different member variables
Hi Experts,
I have to provide an API to users who need to send some command to the server.
the commands will be of the form
class API
{
void sendWrite()
void sendUpdate()
void sendRead()
void sendDelete()
};
I need to construct an object with the following which is the command to be send to a server. The command is of this form(i.e, three separate lines with the following format)
msg:::write
id:::123
data::dataValue
msg is one of write, read, delete, update, etc.
id is not relevant for now.
The dataValue may be a string, int or a json encoded string. I will be setting this data field according the command.
I have another class that actually send this string to the server.
bool cmdSender::sendCommand()
{
}
What I am trying to do is to create the commandMsgs and
do something like
sender->sendCommand(cmd.ge tString()) ;
So, I need to create a Command class and constuct it as per the request. What is the better way to do it.
class Command
{
}
So, I need to create the Command objects by simply passing
Command *cmd = new Command(write, 123, dataValueString);
then call sendCommand(cmd->getString ()) or something like this.
I have to provide an API to users who need to send some command to the server.
the commands will be of the form
class API
{
void sendWrite()
void sendUpdate()
void sendRead()
void sendDelete()
};
I need to construct an object with the following which is the command to be send to a server. The command is of this form(i.e, three separate lines with the following format)
msg:::write
id:::123
data::dataValue
msg is one of write, read, delete, update, etc.
id is not relevant for now.
The dataValue may be a string, int or a json encoded string. I will be setting this data field according the command.
I have another class that actually send this string to the server.
bool cmdSender::sendCommand()
{
}
What I am trying to do is to create the commandMsgs and
do something like
sender->sendCommand(cmd.ge
So, I need to create a Command class and constuct it as per the request. What is the better way to do it.
class Command
{
}
So, I need to create the Command objects by simply passing
Command *cmd = new Command(write, 123, dataValueString);
then call sendCommand(cmd->getString
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I recently used the Factory and Command design patterns for a web-update application. I found them to be a little extra work than the simple design I originally envisaged, but the benefits were realised as I added new types of commands to my application without changing the application logic. The command logic was encapsulated in the new command classes I was creating.
Cheers,
Chris