samedi 26 août 2017

Create interface in python

This is related to pattern design in Python, especially interface building. I need to implement generic interface to handle call and dispatch into specialized functions.

I have this code :

def get_batch(func_name_id="", ddict={}, VERBOSE=0):
    if VERBOSE : print( "get_batch: " + func_name_id)
    try :
      return globals()[func_name_id](ddict)     
    except Exception as e:
      print(e)
      print("No batch  available")
      return []

Main reason is this creates a loose interface with history code, and adding new specialized function does not require changing the core part.

Is it a good way to implement interface in python, what are the potential issues I have to face ?

Aucun commentaire:

Enregistrer un commentaire