vendredi 26 mars 2021

Defensive programming against client code if I myself implement the client code and the Interface?

I'm writing an application in Python. Somewhere, I write a model layer composed with classes, and, any of them, say:

class Orders:

has a bound method whose signature is :

def delete(self, id=None, name=None):

I need id or name not to be None. Then, here is my question:

Since I myself write the model layer and the client code, which would be something like:

model.Orders().delete(id=1234)

Would be good practice to check the parameters inside the delete method with code like:

if not any((id, name)):
    raise ValueError('Order Id or Order name must be provided')

?

I think, since I write the two sides, I will always call the delete method providing one of the parameters avoiding checking and saving a lot of code. I expect the model layer will reach 2 or 3 thousand lines, interfacing a database server.

I put a specific example, but I'd appreciate an answer for the general case.

Aucun commentaire:

Enregistrer un commentaire