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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Mapping a Design to Code 133public void enterItem(int upc, int qty){if (isNewsale()){sale=new Sale();}ProductSpecification spec = prodCatalog.specification(upc);sale.makeLineItem(spec,qty);}8.2.4 Container/collection classes in codeIt is often necessary for an object to maintain visibility to a group of other objects; the need for this isusually evident from the multiplicity value in a class diagram – it may be greater than one. For example, a¿+ÀÁ[Æ must maintain visibility to a group of ¿+ÀÁ[ÆWÂ;Ã]Ä^Å-Æ9ÇWÈXÆDÉ instances, as shown in Figure 8.6.public class sale{...private Vector LineItemsSaledate:Datetime:TimeisComplete:BooleanbecomComplete()makeLineItem()makePayment()total()Contains1 1..*SalesLineItemquantity: Integersubtotal()A container class is necessary to maintainattribute visibility to all the SalesLineItemsFigure 8.6: Reference to a containerIn object-oriented programming languages, these relationships are often implemented <strong>with</strong> the introductionof an intermediate container or collection. The one-side class in the association define a reference attributepointing a container/collection instance, which contains instances of the many-side class.The choice of a container class is influenced by the requirements; key-based lookup requires the use of aãoÀBÂ9ëÈ`ÀÕÁ[Æ , a growing ordered list requires a ú_Æ:ÒÈ ÐÏ, and so on.With these discussions, we can now define the ɈÀBاÆSà ÄLÅ+Æ9ÇWÈXÆÉ method of the ¿+ÀÁ[Æ class as shown in Figure8.7.Note that there is another example of code deviating from the collaboration diagram in this method: thegeneric À Ñ¥Ñmessage has been translated into the Java-specific À Ñ¥Ñ ì¥Á†ÆÉdÆDÅsÈ message.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!