I’m about to write a program in C++, but I’m unsure as to how to go about it. I want to create a program that can be used with a command line frontend but also a GUI frontend as I don’t want to bind a user to a specific interface such as a widget toolkit for dependencies’ sake.
How would be the best way to do this? I know some programs like RSync and SSH have frontends in GUIs, but I’m not sure how this is done. Wouldn’t it be hacky to have a program that just uses system() to run it all while having a pretty GUI?
You implement your program’s algorithms in a library, carefully avoiding any UI stuff. The API to your algorithms is specified in header files.
Then you can write several applications that use this library, one implementing a GUI front end and one a command line interface. They include the headers and compile against the API, and you link the library to it.
Be careful to not to compile the library and the GUI with inconsistent settings.
IME the separation of algorithms from UI can be achieved best when you first implement a command line UI. You might have to employ callbacks for that separation.