jeudi 24 mars 2016

writting better code with python 2.6

I'm writing a big application in python. There is a class A with lots of functions each doing some minor tasks. A handler class/method X will receive some input and call appropriate methods of class A. I want all the functions of class A to do just minor task exluding things like exception handling, pre task validation, post task validation etc. How to design the classes and functions to write clutter free code so that things like exception handling, pre task validation, post task validation are not written into each methods of class A.

For example,

class A:
  function1(self, ..):
    #task1
  function2(self, ..):
    #task2

class Handler:
  # call function1 or function2, also handle exceptions that occur in function1 or function2

I dont want to write try/except in each functions of class A.

Aucun commentaire:

Enregistrer un commentaire