K
key9
Hi All
I 've got no idea how to describe it on subject.
See code:
//ABC
class Keyword{}; // user's command
class Handler{}; // command's action
// A Command contain A Keyword* + A Handler*
class Command{
public:
....
private:
Keyword* kwd_i;
Handler* hnd_i;
};
//...somewhere on code ...
//... here, a real needed keyword & handler class defined ...
class KeywordSon : public Keyword{};
class HandlerSon : public Handler{};
//...ok what I need is a Command ...
//... so what 's the way I can construct Command like as follows?
/*pseudo code*/
Command* cmd_ = new Command(KeywordSon(),HandlerSon());
/*/pseudo code*/
***************
***************
//I don't want code like this
//load
KeywordSon* kwd_;
HandlerSon* hnd_;
Command* cmd_ = new Command(kwd_,hnd_);
//unload
delete cmd_;
delete kwd_;
delete hnd_;
// Some one told me a factory class can solve the problem
// but what about class "KeywordSon" have 10000 types? how I can control
them on code? They are not certain.
// and I can not write a function on a Class.
// so I think , control them by the class name is the way.
//and also I want when I write
delete cmd_;
//all the memory occupied by line "Command* cmd_ = new
Command(KeywordSon(),HandlerSon());"
//can be freed automatic.
Is that possible?
Thany you very much, sorry for my poor English & c++ experience.
key9
I 've got no idea how to describe it on subject.
See code:
//ABC
class Keyword{}; // user's command
class Handler{}; // command's action
// A Command contain A Keyword* + A Handler*
class Command{
public:
....
private:
Keyword* kwd_i;
Handler* hnd_i;
};
//...somewhere on code ...
//... here, a real needed keyword & handler class defined ...
class KeywordSon : public Keyword{};
class HandlerSon : public Handler{};
//...ok what I need is a Command ...
//... so what 's the way I can construct Command like as follows?
/*pseudo code*/
Command* cmd_ = new Command(KeywordSon(),HandlerSon());
/*/pseudo code*/
***************
***************
//I don't want code like this
//load
KeywordSon* kwd_;
HandlerSon* hnd_;
Command* cmd_ = new Command(kwd_,hnd_);
//unload
delete cmd_;
delete kwd_;
delete hnd_;
// Some one told me a factory class can solve the problem
// but what about class "KeywordSon" have 10000 types? how I can control
them on code? They are not certain.
// and I can not write a function on a Class.
// so I think , control them by the class name is the way.
//and also I want when I write
delete cmd_;
//all the memory occupied by line "Command* cmd_ = new
Command(KeywordSon(),HandlerSon());"
//can be freed automatic.
Is that possible?
Thany you very much, sorry for my poor English & c++ experience.
key9