Hi, In my opinion (which is a very modest one compared to some of the geniuses that roam around in this list) you should validate and automatically convert the value if it's of the expected type but out of range (less than 0 gets converted to 0 and more than 100 gets converted to 100). Nevertheless, you should throw some kind of warning back to the user of your component, a simple trace might do the trick.
If the value if of a different type that cannot be cast into to expected type (non-numeric string, null, NaN, etc.) you should throw an error and stop your component from working. I normally do this, because sometimes calculated values that I pass into my components are naturally out of range and, sometimes, the effort of putting them into range might be overkill. Yet, I like to be reminded that this has happened just in case something is wrong. This is, again, just my opinion and I don't have any pretension of being an OOP expert. I've just been doing it for a reasonable amount of time and it has worked well for me and my development team. Rui Duarte Silva Senior Flash Developer / Senior Product Manager MNI - Médicos Na Internet, Saúde na Internet, SA Alert Life Sciences Computing www.alert-online.com -----Mensagem original----- De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Em nome de David Bellerive Enviada: segunda-feira, 25 de Setembro de 2006 15:19 Para: [email protected] Assunto: [Flashcoders] Implicit Setters: Is validation considered a good orbad OOP practice ? I've been reading and learning about OO design & analysis for the past few months and I've just recently started applying what I've learned in my Flash projects ? Learning a new language (like AS3) is no biggie but learning how to code differently (from procedural to OOP) is the real challenge for me ! So here's my first OOP question : When using implicit setter methods (using the set modifier), is it considered a good or bad practice to validate the value passed to the implicit setter method ? For exemple, let's say I'm building a Flash Video Player component and I decide that, amongst others, it must have a volume component parameter which is a Number. In the implicit setter method for the volume, should I validate the value that is passed to this method and make sure it isn't null or undefined, it isn't NaN and that it isn't lower than 0 or higher than 100 ? Which of the following options is best : 1) Do not validate the value and let the user of my component set the volume to undesired values like null, undefined, NaN, -20, 973, etc. Here, the assignment will work as expected whatever the value is (unless it's of another datatype) but the component might fail at runtime since a volume obviously can never be NaN or null for exemple. 2) Validate the value and, if it is null, undefined or NaN, do nothing. If it is lower than 0, set it to 0. If it is higher than 100, set it to 100 ? Here, the assignment might not work as expected if the valus is undesired (like null or NaN for exemple) so this will prevent the component from failing at runtime but the user won't know that his assignment wasn't succesfull. 3) Validate the value and it it's an undesired value, throw an error ? Here, the component prevents the user from assigning and undesired value like NaN or undefined and the user is alerted of the failure at runtime provided that he used a try catch statement. What do you guys think ? __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ [email protected] To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com _______________________________________________ [email protected] To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com

