Question

I have the need to validate some data. Sometimes, the data is repeated in my data structure, sometimes it is singular. When it is multiple, I have a flag set for this. In order to reduce code, I am attempting to do the following psuedocode:

def validate(self):
    if self.multiple
        for chunk in self.data: #not real code here
            validate_one_chunk(chunk)
    else:
        validate_one_chunk(self.data)

My question is the following: validate is a method in a class. validate_one_chunk does not read or modify anything in the class. If the validation fails, it raises an exception, otherwise it does nothing except validate.

Should validate_one_chunk be:

'regular' method in the class

static method in the class

nested inside of validate?

Était-ce utile?

La solution

'regular' method in the class

No.

static method in the class

No.

nested inside of validate

Maybe. If other classes need it then make it a module-level function instead.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top