Amazon Interview Question for SDE-2s


Country: United States
Interview Type: In-Person




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

I will use Inheritance to design furniture shop-

I will create several classes like-

1- Items - Super class of all classes and will have common variable and methods for all items. such as - id,name,price,getprice(),updatePrice,quantity etc. Because these variables and methods will be common for every item.
2- Furniture- This will be the child class of Item class and can also have several child classes, such as-
a- WoodenFurniture
b- SteelFurniture etc.
Furniture class can also have the boolean flag isChildSafe , Because all the furnitures should have inherit the property of furniture class.

Lets come to the future item addition- Lets say Phone, Tablet , Medicines etc.
You can add all these things by creating several new classes and without making any changes in existing system-

3- Electronics - Child class of item and parent class for the Mobile class,Tablet class and other electronics. You can put boolean like isFireSafe ,isWaterSafe etc. in this class Which are applicable for all the child of Electronics class.
4- Medicine - Again child class of Items, and will have some child class if needed.


You can make Items,Furniture,Electronics,Medicine as abstract classes or Interface(Depends on the requirement).
By using this type of design you can expand your system without affecting existing design.

- azambhrgn May 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Designing should be in such a way the client code should not be changed at all, for viewing items, selling items, adding inventory to the store. etc To work out these stuff:-

Define a interface as Inventory.
Start defining the composite object like Furniture Item, Electronics Item etc.
Under these add the Concrete Implementation like chair, table, telephone.
Just think in term of composition under each category,
To add the property at the run time isChildSafe, IsWaterSafe use decorator design pattern.
To iterate to all of the inventory, to sell , view use iterator design pattern.
When doing the iteration, different kind of objects are there use visitor design pattern to execute different algorithms on it.

- Deep June 04, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is a bad design.
Always prefer composition over inheritance.

- t May 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can have two main classes Product and Inventory.
A product can be any type of product like furniture, cosmetics, phone etc..
It can contain all features like isChildSafe, isFragile and so on.
Inventory will be actual physical items kept in the shop. Every inventory will linked to a product. It can have features like availability,area of storage and so on. Product to Inventory will be one to many relationship

- AJ September 06, 2017 | 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