But then you'll end with a class that looks like the current Token class.
Yes. And if it works now, there is no need to hurry for a change. Let the ideas ripen.
the base class may have a pure virtual function named XXXArguments()?
No. The methods should get the necessary things inseparable from the call. Just ordinary arguments.
That makes it easy to understand and to use it right and harder to do it wrong. And it minimizes
state and side effects.
I need to store all the Token* pointers in the TokenTree
...but be aware of who owns them, who deletes them, even in case of exceptions. That's why
alternatives to raw pointers may be an option (see GN2013 Sean Parent). No leaks! No
dangling pointer!
Sorry, I don't understand much well, can you give more details?
e.g. separate the functionality/data in the existing Token Class that does not have to be coupled.
(strive for loose coupling, high cohesion, single responsabilty etc.)
a) class TokenLocation{ wxString name, unsigned int file, unsigned int line, size_t ticket };
b) class TokenTreeItem{
bool AddChild(int childIdx);
bool DeleteAllChildren();
bool HasChildren() const;
}
class Token
{
...
TokenLocation m_Location; // naming needs improvement
TokenTreeItem m_TreeItem;
};
If the interface remains the same, all changes are simply implementation details. The code
could be improved by applying small refactoring steps without affecting client code.
But I found that most books are using Java as examples in the book, not C++.
Yes. And with C++ you are not limited to "true OO-Style". Nevertheless, you could
learn a lot of language independant things from the text. The code-samples are
general enough and easy to understand for a C++-programmer. Just do not to transfer
everything blindly to C++. E.g: in C++, the default is value semantics whereas in
Java and C#, it is reference semantics. That makes quite a difference. Exploit this in
your design (using constness, immutability, minimized state, especially shared one etc).