lundi 6 novembre 2017

approce for design pattern for email parsing

I am struggling to determine if factory pattern is the best arch/solution for this scenario,
I am parsing emails, there are multiple type of emails, each email type has its own parser class, all parser classes extend main abstract parser class that has some common code.

For each Emails I read from the server I call the factory (EmailParserFactory) to get the appropriate Email Parser
The thing is that with factory pattern the factory relies on a common interface (in the classic Java factory pattern the "Shape" is the interface )
But I need to maintain some common logic in my main parser so I need it abstract class.

I am not sure factory pattern is the right way to go here.

The current design I came up with as follow:

EmailParser parser EmailParserFactory.getAppropriateEmailParser(email) ;
ParsedEmail = parser.getParsedEmail(email) -- parser is already the appropriate parser, sending it the email message will get back a parsed object.

Objects:

     EmailParserFactory
        private getEmailType(emailMessage) --    will check email type
                                                    - if email subject contains feedback its a feedback email  
                                                    - if the email contains GUID then  its a reply email etc

    EmailParser         - abstract class
      getBodyText() - common for all 

      ComplaintEmailParser  - specific parser for Complaint Email
        parseEmail()
      FeedbackEmailParser  - specific parser for Feedback Email
        parseEmail()
      ReplyEmailParser  - specific parser for Reply Email
        parseEmail()

Aucun commentaire:

Enregistrer un commentaire