Perl: the Markov chain saw | |
PerlMonks |
Re^2: Reblessing yourselfby Ovid (Cardinal) |
on Apr 17, 2007 at 10:45 UTC ( [id://610496]=note: print w/replies, xml ) | Need Help?? |
When you first call new(), the database is searched to find out if the item exists. If it does, you receive a Product::Real. Otherwise, you receive a Product::Potential. This has the downside that the developer needs to test this in their code:
And no, Product::Real shouldn't call create() again, but since that method won't be defined in the base class, it's guaranteed to fail if called. The benefit of this is that we use Perl's OO mechanisms to determine if we handle a method rather than this obvious, but clunky code:
Effectively, we're testing the type of the object from within the object and that's generally a design flaw. Separating the classes means that Perl does this for us. However, this does mean that outside of the class, developers need to make at least one test of the object type (the 'exists' test) and this concerns me. I like to minimize procedural code as much as possible as it's a constant source of bugs. Cheers, New address of my CGI Course.
In Section
Seekers of Perl Wisdom
|
|