Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to design a command line program reusable for a future development of a GUI? [closed]

Tags:

What are some best practices to keep in mind when developing a script program that could be integrated with a GUI, probably by somebody else, in the future?

Possible scenario:

  1. I develop a fancy python CLI program that scrapes every unicorn images from the web
  2. I decide to publish it on github
  3. A unicorn fan programmer decides to take the sources and build a GUI on them
  4. he/she gives up because my code is not reusable

How to prevent the step four letting the unicorn fan programmer build his/her GUI without too much hassle?

like image 777
systempuntoout Avatar asked Apr 10 '10 12:04

systempuntoout


People also ask

What is CLI and GUI?

A GUI is a graphical representation in which the users can interact with software or devices through clickable icons. A CLI is a console or text-based representation in which the user types commands into a terminal to operate and navigate the software or devices.

Why is the GUI interface easier to use than the CLI?

GUIs offer better multitasking and control Being more user-friendly than a command line (especially for new or novice users), a visual file system is utilized by more people. GUI users have windows that enable a user to view, control, manipulate, and toggle through multiple programs and folders at same time.


1 Answers

You do it by applying a good portion of layering (maybe implementing the MVP pattern) and treating your CLI as a UI in it's own right.

UPDATE

This text from the wikipedia article about the Model-View-Presenter pattern explains it quite well.

Model-view-presenter (MVP) is a user interface design pattern engineered to facilitate automated unit testing and improve the separation of concerns in presentation logic.

  • The model is an interface defining the data to be displayed or otherwise acted upon in the user interface.

  • The view is an interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.

  • The presenter acts upon the model and the view. It retrieves data from repositories (the model), persists it, and formats it for display in the view.

The main point being that you need to work on separation of concern in your application. Your CLI would be one implementation of a view, whereas the unicorn fan would implement another view for a rich client. The unicorn fan, would base his view on the same presenters as your CLI. If those presenters are not sufficient for his rich client he could easily add more, because each presenter is based on data from the model. The model, in turn, is where all the core logic of your application is based. Designing a good model is an entire subject in itself. You may be interested in reading, for example, about Domain-Driven Design, even though I don't know how well it applies to your current application. But it's interesting reading anyway. As you can see, the wikipedia article on MVP also talks about testability, which is also crucial if you want to provide a robust framework for others to build on. To reach a high level of testability in your code-base, it is often a good idea to use some kind of Dependency Injection framework.

I hope this gives you a general idea of the techniques you need to employ, although I understand that it may be a little overwhelming. Don't hesitate to ask if you have any further doubts.

/Klaus

like image 93
Klaus Byskov Pedersen Avatar answered Sep 22 '22 17:09

Klaus Byskov Pedersen