Amazon.com

  www.amazon.com
  www.amazon.com

Interview Question

Software Development Engineer Intern Interview

Write OOP system to parse different type of error formats.

Answer

Interview Answer

2 Answers

0

What is the answer of this question?

Anonymous on Mar 15, 2013
0

Here is what I would answer. I think what they are looking for here is a description of the strategy pattern. But as always I would start out asking questions (like the requirements definition phase).

What is the bigger picture of this component? What sort of system does it live in? Are there specific time or program size constraints? Who are the end users? Who are the clients? How are errors to be parsed delivered?

Without many details, the most flexible implementation of the error parse would be a Strategy which would dynamically allow different parsing algorithms.

I'll define an abstract base class (ErrorParse) with 1...n subclasses (UserErrorParse, SystemErrorParse, FastErrorParse, ScoobyDooErrorParse, ...NErrorParse).

The base class defines the interface for parse which the subclasses will use. Each subclass will implement the "parse" method as it pertains to it. This has a few benefits:

This allows the elimination of a large set of conditionals that would choose which parsing algorithm to use, which would result in better maintainable code.

the derived classes could share common methods.

This would allow a client the ease of altering the parse algorithm at run time to adjust for time or data constraints or perhaps depending on the level of detail a particular client would want. You could even use abstract factory here to define a strategy that matches a suite of other classes that would be specific to a family of clients in the case where you don't want a client deciding which parse implementation it gets to use. Or the client could have some flexibility and specify it wants the error parsed urgently, or with a lot of detail. Using strategy easily accommodates all of that.

Nico on Mar 16, 2013

Add Answers or Comments

To comment on this Question, Sign In with Facebook or Sign Up