Validating objects?
Posted: Thu Nov 10, 2011 3:51 pm
I'm trying to create an invoice class which is heavily dependent upon data from our DB. I've defined some class properties -- account number, invoice number, invoice date, and invoice details -- upon which most of the class methods will rely. The problem, or perhaps one of the problems, is that this data is scattered across numerous tables. Currently, the constructor requires only a single argument: invoice number. If this number does not correspond to a valid invoice number (ie. we have no such invoice) then most of the class methods will fail, including the methods required to assign values to the class properties. These, in turn, also need to point to valid database records.
I'm not really sure how to proceed from here. Does calling all the property setter methods (ie. $this->account_number = $this->getAccountNumber()) in the constructor and throwing exceptions if any of them returns FALSE make sense? Am I thinking about this completely wrong?
I'm not really sure how to proceed from here. Does calling all the property setter methods (ie. $this->account_number = $this->getAccountNumber()) in the constructor and throwing exceptions if any of them returns FALSE make sense? Am I thinking about this completely wrong?