Answer the question
In order to leave comments, you need to log in
How to implement static field/method inheritance if possible?
I am writing a Linux terminal emulator (like Bash) for a coursework. It turns out I created an abstract base class Command.
class Command
{
public:
Command(const std::string&);
std::vector<std::string> getArguments();
std::vector<std::string> getOptions();
virtual void execute(Directory& currentDirectory) = 0;
virtual std::string getCommandName() = 0;
protected:
std::vector<std::string> arguments_;
std::vector<std::string> options_;
void parseStr(std::string);
};
Answer the question
In order to leave comments, you need to log in
First. Explain, for yourself and for me, what is a Command object?
My vision is to separate the Command objects (the user-entered and parsed string) and the Program (the program that implements the command). I also drew - if you want, use it, if you don't want it - the Console object (I / O console) and System (program environment like the current directory, environment variables, file system).
I'm working with values and pointers here, in C++03 terms, but you might be interested in C++11 smart pointers.
std::string commandLine = console.getSomeCommandLine();
Command command;
std::string error;
if (!command.parse(commandLine, error)) {
console.err().writeln(error);
return;
}
Program* program = system.findProgram(command.programName);
if (!program) {
console.err().writeln("Bad command or file name");
return;
}
Console redirectedConsole = console.redirectStreams(command);
program->exec(redirectedConsole, system, command.getArguments());
const std::vector<std::string>& getArguments() const;
const std::vector<std::string>& getOptions() const;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question