samedi 14 février 2015

What pattern is best suited for executing different actions (depending on user input) in python

I want to write a program in python that the user will be able to decide what operation will run at runtime, but also I want to make my program designed well in order to be able to add operations easily. lets say the user inputs "3 4 add" then the output would be 7 and if he write "3 4 mul" then the output would be 12.


please note that i'm not looking for the traditional "if, elif, elif" ect, because I want to make a design that will allow other programmers to easily add operations.


what pattern should I use, and any tips/guide on how to implement it?


thanks.


Aucun commentaire:

Enregistrer un commentaire