Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Objects and validation

Reply
Thread Tools

Objects and validation

 
 
python@lists.fastmail.net
Guest
Posts: n/a
 
      12-12-2010
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?

Thijs
 
Reply With Quote
 
 
 
 
pakalk
Guest
Posts: n/a
 
      12-12-2010
On 12 Gru, 15:28, pyt...@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.
 
Reply With Quote
 
 
 
 
bruno.desthuilliers@gmail.com
Guest
Posts: n/a
 
      12-13-2010
On 12 déc, 15:28, pyt...@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?
>


There's no one-size-fits-all answer to this question. Part of the work
really belongs to the layer that accepts data from the outside world,
part of it belong to the 'model' object itself. In any case, the
'model' object shouldn't have to worry about data conversion etc -
like, if one of the attribute is supposed to be a datetime, it's the
client code's responsability to provide a proper datetime object, not
a string that may (or not) be the textual representation of a date and
time.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. Mark B ASP .Net 2 09-11-2009 07:09 AM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. Dhruba Bandopadhyay ASP .Net 1 05-25-2006 01:06 AM
Using both server side validation and client side validation =?Utf-8?B?dmlkeWE=?= ASP .Net 1 06-02-2005 09:45 PM
objects of objects, vectors and sessions bigbinc Java 3 11-18-2003 09:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57