The thread ‘Group commonly used application-wide methods in unit-test friendly way’ has given me a lot to think about, maybe I’m stuck in procedural mode. But how to get out of the rut? How to think about objects? A “button” is an object, you can do things to it and it will respond in certain ways. An email address is not an object, it’s value, a property of the account owner just like a telephone number or a name.
An email address can be valid or invalid. There are many methods of validating an email address, from less precise to more precise: you can check the formatting, you can look up the MX record, you can send an email to see if it bounces, you can confirm the email address if you get a reply from that address.
If you are dealing with a member, a subscriber, or an account, the email address is their property and you can use all the methods outlined above to verify the email address. If you have a mailing list the email address is still a “property” of the list but not as “proprietary” as in the first case and you can’t use all the validation methods. If you are dealing with a contact form, the visitor’s email address is still a “property” but even less “proprietary” that in the case of a mailing list but at least you have received direct authorization to send mail to that address.
For discussion purposes let’s call the validation anyone can do “secondary” because it’s not entirely conclusive and let’s call the validation that the membership scripts can do “primary” because they get owner feedback. If there are better terms for these things, please let me know.
According to the thread mentioned above, the email validation methods should be part of the membership class that really owns the email address property. But there can be many versions or variations of the membership class and the validation methods should be in some ancestral membership class which can be used by contact class and mailing list class as static methods, for example:
$myList->valid('Id15') = Membership::validateEmail($myList->getEmail('Id15'));
There would be a base “Membership class” which can be extended for specific membership needs like 'ForumMembership extends Membership"
This would eliminate the need for an email utility class. Each calling class would deal with errors in their particular way. This requires that the validation and feedback methods be separate.
Am I making sense?