我有一個設計問題:設計問題:枚舉或函數或別的東西,
我有以下整數集的像一些命令:
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:
...
}
我應該怎麼辦?
有沒有其他好方法? 謝謝。