16.4. ReceivedMailExaminer

The responsibility of the ReceivedMailExaminer is to examine the mail and determine if it is acceptable. The ReceivedMailExaminer delegates the actual examination to objects implementing the MailExaminer interface ("Separating Concerns Makes Smaller Concerns"), shown in Example 16-4.

Example 16-4. MailExaminer interface
    interface MailExaminer
        UnacceptableRating examine_mail(MailDTO a_mail_dto,
            MailReport a_report)

The UnacceptableRating returned by the examine_mail( ) method of MailExaminer is compared by the ReceivedMailExaminer to a configuration setting to see if the mail should be considered spam. If so, the appropriate response is returned to the ConnectionHandler.

On construction, the ReceivedMailExaminer calls the MailExaminerFactory. The MailExaminerFactory method checks configuration information to see what examiners are requested, creates the appropriate examiners, and returns a reference to an examiner. This reference might be to the only one, to a composite one, or to a DefaultMailExaminer.

The composite pattern (see Design Patterns by Erich Gamma et al.) is used if multiple MailExaminers are desired. If the configuration calls for multiple examiners, MailExaminerFactory creates a MultipleMailExaminer:

    MultipleMailExaminer implements MailExaminer
        add_examiner(MailExaminer an_examiner)
        // plus methods in MailExaminer

The MailExaminerFactory adds each specified MailExaminer to the MultipleMailExaminer object.

When an examine method is ...

Get Prefactoring now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.