Amazon Interview Question
Software Engineer / DevelopersUser(id long pk, username string, password string, email string)
Movie(id long pk, order_id fk, title string, year short, genre string, category string)
Order(id long pk, userId long fk, dateOfRent date, dateOfReturn date, active boolean)
Order_Payment(id long pk, amount double, order_id long fk, success boolean)
StarCast(id long pk, name string, movie_id long fk)
Role(id long pk, title string, star_id long fk)
My solution:
Before design the Classes; I would consider designing a database for this system. Once developed, it would obviously simplify the Classes Design [Consider composition, inheritance and delegation]. Consider creating Interface for most of the classes for extensibility. Consider creating Abstract class and inherit methods and properties from it; if there is a code reusage.
The major design patterns to be considered are:
1. Singleton for Processing classes
2. Data Access Objects for Database
3. Plain Old Java Objects for Database
4. Entity Classes for Database
5. Util Classes for Delegation
and there are few I don't know. :)
Order(id long pk, userId long fk, rentedOn date, returndate date)
- Amol March 20, 2011payment(id long pk, amount double, paid boolean)
User(id long pk, username string, password string, email string)
user_order(userid long references user(id), order_id long references order(id)) 1:m
order_payment(order_id long references order(id), payment_id references payment(id)) 1:m
Movie(id long pk, name string, year short)
Order_movie(order_id long references order(id), movie_id long pk references movie(id)) 1:m
StarCast(id long pk, name string)
Movie_starcast(movie_id long references movie(id), cast_id long references starcast(id))
role(id long pk, title string)
cast_role(cast_id id fk references starcast(id), role_id fk references role(id)) 1:m