Recently I came across below link which lists top 5 OOAD questions (and answers also).
Top 5 Object Oriented Design Interview Questions for Programmers and Engineers
I have decided to give a try one problem at a time.
Following is my first try for the problem (Design a Vending Machine in Java)
Vending Machine :
The solution is centered among below three classes .
1)Product : Abstract class for Product. The actual products (like NUTS,CANDY) are derived
from abstract class
2)Currency : Since price for products can be 1,5,10,15 cents as well as 1,2 dollar , currency
class models denomination (cents/dollar) and value (1/2/10)
Curreny class will have required routines like subtract , compareTo for currency related
operations
3)Deliverable : It contains Product and Currency classes since the change (user input amount - product amount) also need to be delivered along with requested product.
3)VendingMachine : Core class supporting vending machine operations.
The class diagram for solution is given below
Comparing the solution with answer given Design a Vending Machine in Java - Interview Question
I have derived below Pros and Cons of both solutions.
Pros :
1)Currency and Products classes are modeled better as compared to solution given.
The various denominations and value has not been modelled in solution.
The operations pertaining to amount calculation are moved to Currency class.
Products can be added easily without more modifications since they are encpsulated behind abstract class.
2)The VendingMachine has state associated with it . The vending machine goes through various states as it performs varipus operations.
e.g: It cannot deliver product if it is not in CURRENY_ACCEPTD state. This ensures that random operations are not allowed.
Cons :
1)I completely missed maintaining inventory of Products. The solution also maintain inventory of COINS as coins can also be run out of stock.
2)I deliberately didn't code VendingMachine to any interface or abstract class since I treated it as a concrete concept rather than abstraction.
What still needs to added :
1)Junits Need to be added for all scenarios. Currently added for only testAcceptCurency and testGetProduct.
2)Detailed exception handling
The code for the above solution is available on bitbucket on repository - https://joshiaatul24@bitbucket.org/joshiaatul24/ooad-probs-solns.git
Top 5 Object Oriented Design Interview Questions for Programmers and Engineers
I have decided to give a try one problem at a time.
Following is my first try for the problem (Design a Vending Machine in Java)
Vending Machine :
The solution is centered among below three classes .
1)Product : Abstract class for Product. The actual products (like NUTS,CANDY) are derived
from abstract class
2)Currency : Since price for products can be 1,5,10,15 cents as well as 1,2 dollar , currency
class models denomination (cents/dollar) and value (1/2/10)
Curreny class will have required routines like subtract , compareTo for currency related
operations
3)Deliverable : It contains Product and Currency classes since the change (user input amount - product amount) also need to be delivered along with requested product.
3)VendingMachine : Core class supporting vending machine operations.
The class diagram for solution is given below
Comparing the solution with answer given Design a Vending Machine in Java - Interview Question
I have derived below Pros and Cons of both solutions.
Pros :
1)Currency and Products classes are modeled better as compared to solution given.
The various denominations and value has not been modelled in solution.
The operations pertaining to amount calculation are moved to Currency class.
Products can be added easily without more modifications since they are encpsulated behind abstract class.
2)The VendingMachine has state associated with it . The vending machine goes through various states as it performs varipus operations.
e.g: It cannot deliver product if it is not in CURRENY_ACCEPTD state. This ensures that random operations are not allowed.
Cons :
1)I completely missed maintaining inventory of Products. The solution also maintain inventory of COINS as coins can also be run out of stock.
2)I deliberately didn't code VendingMachine to any interface or abstract class since I treated it as a concrete concept rather than abstraction.
What still needs to added :
1)Junits Need to be added for all scenarios. Currently added for only testAcceptCurency and testGetProduct.
2)Detailed exception handling
The code for the above solution is available on bitbucket on repository - https://joshiaatul24@bitbucket.org/joshiaatul24/ooad-probs-solns.git
No comments:
Post a Comment