Objects and validation

pakalk pakalk at gmail.com
Sun Dec 12 11:03:32 EST 2010


On 12 Gru, 15:28, pyt... at lists.fastmail.net wrote:
> I have a routine in Python which is extracting information from a
> website. This information is read and inserted into objects.
>
> I currently have all the validations and checks implemented in the
> routines which are reading the HTML and creating the objects. It is
> however also possible to move all the validations into the class itself.
> What is considered the best practice for this: validation in the
> functions which read the information and creates the objects or in the
> class itself?

setter

Data sources may differ, and may be used for many reasons, so
validating data there is not a good idea. Object has to keep correct
data, so it should validate it. If you want to have object created no
matter what, you can add validate() method, but you may also use
setters for this - error will be raised every try to set wrong data.



More information about the Python-list mailing list