我有一个设计问题:设计问题:枚举或函数或别的东西,
我有以下整数集的像一些命令:
addition = {2,3,4,5}
subtraction = {3,6,9}
其中添加的优先级>那子。
,所以我创建的类似
class Command{
int priority;
public:
bool operator <(const Command &com);
bool isInSet(int);
// i donot want this to be int ,
// may be tommorrow i go for strings or char.
// How to do this. AND
void execute(int); // should it be here?
};
由于这些命令上的数据结构进行操作。
每个命令都应该知道如何执行iteself,即应该有一个函数使命令本身无用。
如果execute()进入Command中,它将如何访问数据结构?所以Command应该有一个指向这个DS的指针。
或应该是一对,但然后类执行将需要指向DS的指针。
还是应该像命令将我一些枚举,然后切换它像做
enum {PUSH, POP};
while(!commands[i].isInSet(3))
++i;
switch(comands[i].getName())
{
case PUSH:
// operations on DS i have all of them in this scope. :)
case POP:
...
}
我应该怎么办?
有没有其他好方法? 谢谢。