I
Ian Giblin
I am an experienced C programmer, learning C++ by writinging a
mathematical toolkit in the framework of a script interpreter. I am
posting here to ask for advice (or references) on the object design
and implimentation.
Currently I have a portable "ScriptSession" class which contains the
mechanics of looping with a user prompt, parsing a sentence and
handling syntax errors, etc., and I wan this to be a class I can use
for any script interpreter.
One of the core functions is the execution of a command sentence. This
necessarily involves some mathematical commands which should not be
part of "ScriptSession" so I started by overloading a method called
interpret, which is virtual in the base class:
class ScriptSession
{
public:
...
virtual bool ScriptSession::execute(void);
}
I have then written a method within the final application which
overload this, but it needs to know a lot about the internals of the
ScriptSession class so it has become rather ugly and feels like it is
voilating encpasulation and so on. Also, I have put everything in
here, even basic stuff like interpretation of the command "exit" which
is universal, so that won't do.
I bought "Design Patterns" (Gang of Four) but none of the patterns
seem to really fit this nicely. Or maybe I'm just missing some of the
important stuff. I apologise if I haven't explained the problem
clearly enough; that's part of the problem of course.
Any advice would be appreciated. Thanks,
Ian Giblin.
mathematical toolkit in the framework of a script interpreter. I am
posting here to ask for advice (or references) on the object design
and implimentation.
Currently I have a portable "ScriptSession" class which contains the
mechanics of looping with a user prompt, parsing a sentence and
handling syntax errors, etc., and I wan this to be a class I can use
for any script interpreter.
One of the core functions is the execution of a command sentence. This
necessarily involves some mathematical commands which should not be
part of "ScriptSession" so I started by overloading a method called
interpret, which is virtual in the base class:
class ScriptSession
{
public:
...
virtual bool ScriptSession::execute(void);
}
I have then written a method within the final application which
overload this, but it needs to know a lot about the internals of the
ScriptSession class so it has become rather ugly and feels like it is
voilating encpasulation and so on. Also, I have put everything in
here, even basic stuff like interpretation of the command "exit" which
is universal, so that won't do.
I bought "Design Patterns" (Gang of Four) but none of the patterns
seem to really fit this nicely. Or maybe I'm just missing some of the
important stuff. I apologise if I haven't explained the problem
clearly enough; that's part of the problem of course.
Any advice would be appreciated. Thanks,
Ian Giblin.