Amazon Interview Question
Software Engineer / DevelopersClass Store
{
String location
int phone
int branch_id
String email
ArrayList<Cloth> cloth;
add(cloth)
{
//add barcode and price to Hash
}
// for purchase and return
Hash<cloth.barCode, cloth.price>
//methods that returs arraylist of clothes
ArrayList<cloth> getCloth(cloth.type)
ArrayList<cloth> getCloth(cloth.size)
ArrayList<cloth> getCloth(cloth.brand)
}
Class Cloth
{
String brand
enum size {S, M, L, XL, XXL}
enum type {TShirt, Shirt, Pant, Jeans,..}
float price
long barCode
Cloth()
Cloth(type)
}
Class Customer
{
buyCloth(Cloth.barCode, PaymentObj)
{
//get price
//returns Payment receipt number
}
returnCloth(Cloth.barCode) {}
}
Class Staff{}
Class Payment
{
int receiptN
}
Let me know if this design is good!
Yeah, pretty much what I also told the interviewer, But I also had a department class, for different departments like mens women's kid's etc...and had a search method in this class which was then overloaded in 2 other classes that I had for brand and type of clothing(shirt, jeans, outerwear etc) and had these classes inheriting from Department.
But this is an open ended question so I think your solution is also good enough.
Yeah, pretty much what I also told the interviewer, But I also had a department class, for different departments like mens women's kid's etc...and had a search method in this class which was then overloaded in 2 other classes that I had for brand and type of clothing(shirt, jeans, outerwear etc) and had these classes inheriting from Department.
But this is an open ended question so I think your solution is also good enough.
Yeah, pretty much what I also told the interviewer, But I also had a department class, for different departments like mens women's kid's etc...and had a search method in this class which was then overloaded in 2 other classes that I had for brand and type of clothing(shirt, jeans, outerwear etc) and had these classes inheriting from Department.
But this is an open ended question so I think your solution is also good enough.
I suggest using a Factory Method pattern to make the design more flexible and extendible. You can have an abstract class Clothes, which has properties such as price, brand, size, etc. and different kinds of clothes subclass it, overloading price() and brand(). This has the benefit that the store could sell objects of type Clothes, and through runtime polymorphism resolve what kind of clothes to sell. A hash table or a map in the Store class could help finding what sizes of clothes are in-stock.
- PC May 01, 2011To take this further, we might also consider Abstract Factory pattern to be able to sell families of clothes such as shirts, underwear, dresses, jackets, etc. and to account for more flexibility with respect to later additions of clothes to the store and modifications.