Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oct 200391.3913 Ron McFadyen Visibility Visibility: the ability of one object to see or have a reference to another object. e.g. When a register object.

Similar presentations


Presentation on theme: "Oct 200391.3913 Ron McFadyen Visibility Visibility: the ability of one object to see or have a reference to another object. e.g. When a register object."— Presentation transcript:

1 Oct 200391.3913 Ron McFadyen Visibility Visibility: the ability of one object to see or have a reference to another object. e.g. When a register object sends a message to a sale object, the register must have visibility to the sale. enterItem() :Register:Sale makeLineItem() Register has to know about sale in order to send this message. The sale must be visible to the register.

2 Oct 200391.3913 Ron McFadyen Consider an example from Applying UML & Patterns. Some business rules: A register has access to a product catalog A product catalog contains product descriptions A register captures a sale A sale contains sales line items A sale is paid by a payment A product description describes a sales line item

3 Oct 200391.3913 Ron McFadyen ProductDescription Register endSale() enterItem() makeNewSale() makePayment() Payment amount description price quantity ProductCatalog Sale SalesLineItem date makeLineItem() makePayment() getTotal() paid by contains captures contains has access to describes

4 Oct 200391.3913 Ron McFadyen Visibility Visibility from A to B can occur in four ways: Attribute B is an attribute of A (most common) Parameter B is a parameter of a method of A Local B is a non-parameter local object in a method of A Global B is globally visible

5 Oct 200391.3913 Ron McFadyen Suppose Register has a method enterItem(). Suppose further that enterItem() in Register has an attribute that will hold a product description. When the method ends, the attribute value is lost. Visibility is temporary – while the method executes. The visibility is local to the method. public class Register private ProductCatalog catalog; private Sale currentSale; … public void enterItem (ItemID id, int quantity) { ProductDescription desc = catalog.getProdDesc(id); currentSale.makeLineItem (desc, quantity); } Note there is attribute visibility to ProductCatalog and Sale.

6 Oct 200391.3913 Ron McFadyen Suppose Register sends the product description as a parameter to Sale and sale sends that to SalesLineItem. Sale has parameter visibility to ProductDescription. public class Sale private List lineItems = … ; private Date date; Private Payment payment; … public void makeLineItem (ProductDescription desc, int quantity) { lineItems.add (new SalesLineItem(desc, quantity)); } Note there is attribute visibility to SalesLineItem and Payment.

7 Oct 200391.3913 Ron McFadyen If the visibility is non-attribute visibility, we show the relationship as a dependency using a dashed line ProductDescription Register Sale SalesLineItem endSale() enterItem() makeNewSale() makePayment() date makeLineItem() makePayment() getTotal() Payment amount paid by contains captures description price quantity Attribute visibility Non-attribute visibility ProductCatalog contains has access to describes


Download ppt "Oct 200391.3913 Ron McFadyen Visibility Visibility: the ability of one object to see or have a reference to another object. e.g. When a register object."

Similar presentations


Ads by Google