13.07.2015 Views

Object-Oriented Software Development with UML - UNU-IIST ...

Object-Oriented Software Development with UML - UNU-IIST ...

Object-Oriented Software Development with UML - UNU-IIST ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Mapping a Design to Code 1298.2.1 Defining a class <strong>with</strong> methods and simple attributesConsider the class ¿+ÀÁ[ÆWÂ;Ã]Ä^Å_ÈXÆ Ï ÇWÈXÆDÉ and the partial design class diagram in Figure 8.2. A mapping of thepublic class SalesLineItem{public SalesLinteItem(ProductSpecification spec, int qty);public float subtotal();private int quantity}SalesLineItemquantity:Integersubtotal():Quantity* Described-by 1ProductSpecificationdescription:Textprice:Quantityupc:UPCFigure 8.2: ¿+ÀÁ[ÆWÂ:à ÄLÅ+Æ9ÇWÈXÆÉ in Javaclass box for ¿+ÀÁ[ÆWÂ;Ã]Ä^Å-Æ9ÇWÈXÆDÉ in the design diagram to the basic attribute definitions and method signaturesfor the Java definition of¿-ÀÁ†ÆDÂ;Ã]Ä^Å+ÆSÇWÈXÆDÉ is straightforward.Note that, we had to add the constructor¿-ÀÁ†ÆDÂ;Ã]Ä^Å+ÆÄLÈXÆɉ֦ʆʆÊi× Java because of the fact aÒ Ï Æ9À§ÈXÆÖ¤Ầ Ó•Æ9Ò§åËÈTÍJ×thatmessage is sent to ¿+ÀÁ[ÆWÂ:à ÄLÅ+Æ9ÇWÈXÆÉ a in ÆÅsÈXÆ Ï ÇWÈXÆDÉ the collaboration diagram. This indicates, in Java, that aconstructor supporting these parameters is required.Observe also that the return type for the ÂWÌ•ÕÈ Ð È`ÀÁ method was changed from óFÌJÀÅsÈTÄTÈTÍ to a simpleùÐ À§È .This implies the assumption that in the initial coding work, the programmer does not want to take the timeto implement a óFÌ•À§ÅsÈTÄLÈTÍ class, and will defer that.8.2.2 Add reference attributesA reference attribute is an attribute that refers to another complex object, not to a primitive type such as aString, Number, and so on.The reference attribute of a class are suggested by the associations and navigability in a designclass diagram.For example, a ¿+ÀÁ[ÆWÂ:à ÄLÅ+Æ9ÇWÈXÆÉ has an association to a ÎFÏ;ÐÑ ÌJÒÈL¿§ÓJÆ:ÒÄÔQÒSÀ§ÈTÄ Ð Å , and <strong>with</strong> navigability to it.This navigability is needed for sending the messageÓÏ Ä˜ÒSÆ to the ÎFÏ;ÐÑ ÌJÒÈL¿§Ó•Æ:ÒÄÔxÒ9À§ÈTÄ Ð Å from the¿+À§Á†ÆDÂ;à ÄLÅ+ÆSÇWÈXÆDÉin the collaboration diagram for È Ð È`À§Á of the ¿+ÀÁ[Æ . In Java, this means that an instance variable referring toa ÎFÏ;ÐÑ ÌJÒÈL¿§ÓJÆ:ÒÄÔQÒSÀ§ÈTÄ Ð Å instance is suggested.Report No. 259, July 2002<strong>UNU</strong>/<strong>IIST</strong>, P.O. Box 3058, Macau

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!