Amazon Interview Question for Software Engineer Interns


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

This seems like a question to check composition and inheritance concepts. Design should be flexible enough to accomodate future changes. Keeping this in mind we can design a base class which will base for any element to be stored on the shelf bringing in inheritence. Shelf is a separate class having fields to identify allowable types that can be stored on the shelf. Shelf class can contain any collections to allow adding and removing objects from it.

abstract class Base{
.........
}

class Book extends Base implements PrintedMediumInt{
....................
}

Class DVD extends Base implements ElectronicMedia{
....................
}

class Shelf{

ArrayList <Base> collection;
}

Inheritence is used for object creation and shelf uses composition. In addtion object creation can be done via abstract factory. Further extension for CD/DVD/Blueray can be achieved using decorators.

- Abh September 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wouldn't it be more advantageous to make an interface that is something along the lines of IStorable which describes the methods each object might need to interact with the shelf/other objects? Then the shelf would hold IStorable objects which decouples what type of object can be stored rather than having to inherit from Base.

- Canadialad December 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have come up with a solution which you can be found here. thought-works.blogspot.in/2013/12/object-oriented-design-for-library-to.html

- sriniatiisc December 31, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More