This is a question from IBM pre-assessment exam: eStore.com sells small appliances over the Internet. Currently, the store's catalog includes over 50 appliances from 10 different suppliers. A partial class diagram is shown in Figure Sample 1. There are two new requirements for eStore.com: discounts for damaged goods, and searches by size and color. Using Figure Sample 2, which of the following is the BEST way to extend the class diagram to handle these requirements? http://certify.torolab.ibm.com/figures/test486F20.gif a) No changes are needed due to these requirements. b) Create a new class "PhysicalProduct" that represents an actual product in the warehouse. Associate the PhysicalProduct with its related InventoryProduct. c) Add new capabilities to the Inventory class for the management of its Products. d) Extend the InventoryProduct class to handle the new requirements. My answere b. My reason is that isDamaged() should be a feature of a physical product. Any other opinion? [This message has been edited by Caroline Iux (edited May 20, 2001).]
Junilu Lacar
Ranch Hand
Joined: Feb 26, 2001
Posts: 3008
posted
0
I would say the best answer would be B, too. Junilu
It is better not to assume the type of Product (brittle, physical ,etc.).Let's provide these methods/attributes in the more generic class -InventoryProduct to allow greater flexibility in the future.
Since the nature of the goods is not specified, there is not enough justification that the new requirement is for PhysicalProduct only - May be for other goods also - who knows - Hence providing these features in would-be super class seems better.
Hope this helps, Sandeep [This message has been edited by Desai Sandeep (edited May 21, 2001).]
<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Lancy Mendonca
Ranch Hand
Joined: Aug 08, 2000
Posts: 54
posted
0
I would also go for option D. It is difficult to understand why an additional class 'Physical Products'is required when 'Inventory Products' can do the job. The way I understand 'Inventory Products' is a software class for the products sold by estore and hence should be the class with the responsibility for determining if it is damaged and hold size and color attributes
Sun Certified Java Programmer<BR>Oracle Certified DBA
Laojar Chuger
Ranch Hand
Joined: Dec 20, 2000
Posts: 111
posted
0
This is a typical situation for the visitor pattern, which handles when a new functionality is needed. The solution is to create a new class/object for the new functionality. So the answer is B.
Desai Sandeep
Ranch Hand
Joined: Apr 02, 2001
Posts: 1157
posted
0
Laojar, How would you say that the new class would be a "PhysicalProduct" not a "BrittleProduct" from the question?It is not possible to classify the "InventoryProduct" given the problem.Hence I will settle for D. -- Sandeep [This message has been edited by Desai Sandeep (edited May 22, 2001).]
Caroline Iux
Ranch Hand
Joined: May 14, 2001
Posts: 103
posted
0
Note InventoryProduct has an attribute of amountOnHand, which implies InventroryProduct is a generic class for a type of products. For example, it represents all blue size 12 Survivor T-shirts. So to add isDamaged() to InventoryProduct is not reasonable cause we need able to tell which T-shirts is damaged. To extend InventoryProduct class means the subclass will have the amountOnHand attribute too, thus makes me think (D) is not correct. My 2 cents. [This message has been edited by Caroline Iux (edited May 23, 2001).]
Paul Ralph
Ranch Hand
Joined: Aug 10, 2000
Posts: 303
posted
0
Caroline: My reason exactly; you beat me to it. Desai: How could a product that is not a physical product be damaged? It could be a BrittleProduct, but that is not one of the options given. Furthermore, BrittleProduct would just be a subtype of PhysicalProduct. So, with those two thoughts in mind, my answer is definitely B. Paul R
I wanna be a sheriff when I grow up.
Desai Sandeep
Ranch Hand
Joined: Apr 02, 2001
Posts: 1157
posted
0
Hi, I would suggest to consider this problem on "as-is" basis.Any Inventory Product could be damaged.The isDamaged() method could be interpreted in a more generic term - inferior quality products. We can have isDamaged() method in the super class and can override this method in any of the future sub-classes.This would allow more flexibility in the future. If the subclass represents a T-shirt, I will find out if it is torn in my sub class.If it is, I will return true from the subclass isDamaged() method, suggesting that T-shirt is actually damaged and is not of production quality. We may have the internal representation (attribute) of the sub class as per requirements of the class, but one common behaviour across relatively similar classes (all of them would be InventoryProducts) would ensure the methods are kept in manageable proportions. Hope this helps, Sandeep Infact, I would have liked the examiner give one more option on this, i.e. isDamaged() in the Purchasable interface.This is a responsibility which all InventoryProducts have to implement.The Inventory would consider the InventoryProduct, if and only if isDamaged is false.All the subclasses - Physical,Brittle,T-shirts, etc. would polymorphically override this method to determine the quality of the product. Thanks, Sandeep Added reasoning for another possible option which I consider relevant in this case - isDamaged() method in the Purchasable interface. [This message has been edited by Desai Sandeep (edited June 03, 2001).]
Desai Sandeep
Ranch Hand
Joined: Apr 02, 2001
Posts: 1157
posted
0
Please let me know your views on my post above.My answer is D. Thanks, Sandeep [This message has been edited by Desai Sandeep (edited June 03, 2001).]
Caroline Iux
Ranch Hand
Joined: May 14, 2001
Posts: 103
posted
0
Anyone who got 100% on pre-assessment exam? Desai? Maybe you are sure about the answer now. I am trying to update the list of IBM questions with answers. Thanks!
Desai Sandeep
Ranch Hand
Joined: Apr 02, 2001
Posts: 1157
posted
0
Caroline, You guessed it right.I have scored 100% in the pre-assessment test.Infact, I had planned to post the correct answers with analysis for all the questions of the pre-assessment test after passing Test 486. Your earlier answer B for this question was correct . I had given some thought on this question as to why B is correct. The best way to tackle such questions (as well as likes of Student,Instructor ) is to think in terms of instances
Ask what are the instances of InventoryProduct - Cement,Kerosene,Shirts,Books,Crockery,etc.
Ask what are the instances of PhysicalProduct - Utensils,Crockery,etc.
Look at the instances and see if you can classify them as different types.If you can classify the instances as different types,then represent them as a subtype of your supertype.In this case we can say PhysicalProduct is infact a subtype of InventoryProduct due to following reasons:
It has additional properties (like size and color) of interest.
It has an additional operation (isDamaged()) of interest.
Also,you can classify the instances into other subtypes like BrittleProducts(glass items),LiquidProducts(kerosene), etc., which may have disjoint attributes and operations from that specified in the PhysicalProduct subtype as well as InventoryProduct supertype.
Also, as Larman suggests, we need to ask if these subtypes are valid or not.They are because, they satisfy:
100% conformance rule.The association of InventoryProduct with Inventory would also be valid for any of the subtypes of InventoryProduct, viz., PhysicalProduct,LiquidProduct,etc also.The amountOnHand attribute defined for InventoryProduct is also valid for any of the subtypes.
is-a rule.We can say "PhysicalProduct is a kind of InventoryProduct" or "LiquidProduct is a kind of InventoryProduct"
Hence, B is correct. But the most interesting thing is to analyse why D is incorrect? As Larman suggests, one of rule for creating a supertype should be of factoring the commonality (attributes and associations) of its subtypes.
Ask "Are size and color common attributes of InventoryProduct which could be factored for all the subtypes?
Ask "Is isDamaged() common operation for the InventoryProduct which could be factored for all the subtypes?
The answer is "NO".How do I say that?Look at the instances. Is it correct to say:
Kerosene isDamaged(), or,
Cement has size, or,
Books have color.
All the above statments are incorrect.These attributes and operations are very much specific to a disjoint subtype of InventoryProduct ,i.e. PhysicalProduct. To reiterate, put only those attributes and operations in the supertype which are applicable to all its instances Hence D is not the correct answer. C is incorrect for a very obvious reason that the attributes (size and color) and operation(isDamaged()) belong to InventoryProduct types and not Inventory types. A is incorrect since we can say with the discussion above that changes are needed due to these requirements. Hope this helps, Sandeep [This message has been edited by Desai Sandeep (edited June 10, 2001).]