Original Post
hi, several weeks ago i wrote a simple assembler in c++. last night i was going over the source and i realized that i've done some very bad design decisions, here it is: the assembler contains a lexical analyzer and a syntax analyzer, as anybody knows about lexical analyzers its job is to transform a stream of characters into a stream of tokens, and the job of the syntax analyzer is to transform the stream of tokens from the lexical analyzer into a stream of instructions.(actually a parse tree but that's an assembler not a compiler) here is my set of classes: class Token { public: virtual bool IsMnemonic() = 0; virtual bool IsRegister() = 0; virtual bool IsIdentifier() = 0; virtual bool IsInteger() = 0; virtual const char* GetString() = 0; virtual int GetInteger() = 0; }; class Mnemonic : public Token { public: bool IsMnemonic() { return true; } bool IsRegister() { return false; } bool IsIdentifier() { return false; } bool IsInteger() { return false; } const char* GetString() { return _mnemonic; } int GetInteger() { return 0; } private: char* _mnemonic; }; class Integer : public Token { // the same as mnemonic except that GetString returns 0 while // GetInteger returns the _integer member }; class Identifier : public Token { // u get the idea }; class Register : public Token { // bla bla }; // then here is my lexical analyzer interface (not abstract i mean operations) class LexicalAnalyzer { public: void Analyze(const char* assemblyListing, SymbolTable* symbolTable, std::list* tokenList); // rest of the class }; now i want to add another kind of Token like Real so i'll have to add an IsReal() and GetReal() in the Token interface then inherit a Real class from the Token interface and when i begin to use it i must change the LexicalAnalyzer::Analyze() and also the SyntaxAnalyzer::Analyze() so my problem is (1)i need another way so that i could just inherit a new class from the Token interface without changing it and also without changing the LexicalAnalyzer and the SyntaxAnalyzer. (2)is there any possible way that i wouldn't need the Is*() operations which is one way of removing the dependency of the SyntaxAnalyzer::Analyze() method on the different kinds of tokens. someone i know suggested the visitor pattern but i couldn't figure out how to use it in this situation. thanx in advance