OOP Design Question - Where/When do you Validate properties?
Posted
by JW
on Stack Overflow
See other posts from Stack Overflow
or by JW
Published on 2010-04-09T18:47:10Z
Indexed on
2010/04/09
18:53 UTC
Read the original article
Hit count: 391
I have read a few books on OOP DDD/PoEAA/Gang of Four and none of them seem to cover the topic of validation - it seems to be always assumed that data is valid.
I gather from the answers to this post (http://stackoverflow.com/questions/1651964/oop-design-question-validating-properties) that a client should only attempt to set a valid property value on a domain object.
This person has asked a similar question that remains unanswered: http://bytes.com/topic/php/answers/789086-php-oop-setters-getters-data-validation#post3136182
So how do you ensure it is valid? Do you have a 'validator method' alongside every getter and setter?
- isValidName()
- setName()
- getName()
I seem to be missing some key basic knowledge about OOP data validation - can you point me to a book that covers this topic in detail? - ie. covering different types of validation / invariants/ handling feedback / to use Exceptions or not etc
© Stack Overflow or respective owner