O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

15 Visibility

  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

15 Visibility

  1. 1. TK2023 Object-Oriented Software Engineering CHAPTER 15 Designing for Visibility
  2. 2. INTRODUCTION <ul><li>Visibility is the ability of one object to see or have reference to another. </li></ul><ul><li>A sender object can send a message to a receiver object only if the receiver is visible to the sender. </li></ul><ul><li>Example: </li></ul><ul><li>The Sale object is visible to the Register object. </li></ul>: Register : Sale 1: setComplete(true)
  3. 3. <ul><li>When creating a design of interacting objects, it is necessary to ensure that the necessary visibility is present to support message interaction. </li></ul><ul><li>There are four common ways to make an object visible to another: </li></ul><ul><ul><li>Attribute visibility </li></ul></ul><ul><ul><li>Parameter visibility </li></ul></ul><ul><ul><li>Local visibility </li></ul></ul><ul><ul><li>Global visibility </li></ul></ul>
  4. 4. ATTRIBUTE VISIBILITY <ul><li>Attribute visibility from A to B exists when B is an attribute of A. </li></ul><ul><li>It is a relatively permanent visibility as it persists as long as A and B exist. </li></ul><ul><li>Example: </li></ul><ul><ul><ul><ul><li>class Register { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>private ProductCatalog catalog; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>public void enterItem(String itemID, int qty) { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>desc = catalog.getProductDescription(itemID) ; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul>
  5. 5. PARAMETER VISIBILITY <ul><li>Parameter visibility from A to B exists when B is passed as a parameter to a method of A. </li></ul><ul><li>It is a relatively temporary visibility because it persists only within the scope of the method. </li></ul><ul><li>Example: </li></ul><ul><ul><ul><ul><li>class Sale { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>public void makeLineItem( ProductDescription pd , int qty) { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>sl = new SalesLineItem( pd , qty); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul>
  6. 6. <ul><li>It is common to transform parameter visibility to attribute visibility. For example, </li></ul><ul><ul><ul><ul><li>class SalesLineItem { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>private ProductDescription desc; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>public void makeLineItem( ProductDescription pd , int qty) { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>desc = pd; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul>
  7. 7. LOCAL VISIBILITY <ul><li>Local visibility from A to B exists when B is declared as a local object within a method of A. </li></ul><ul><li>Like parameter visibility, it is a relatively temporary visibility as it persists only within the scope of the method. </li></ul>
  8. 8. <ul><li>Example 1: </li></ul><ul><ul><ul><ul><li>class Store { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>public Store() { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>ProductCatalog pc = new ProductCatalog(); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul>
  9. 9. <ul><li>Example 2: </li></ul><ul><ul><ul><ul><li>public class MyApplet extends JApplet { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>public void init() { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Container contentPane = getContentPane(); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>contentPane.add(btnNext); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul>
  10. 10. <ul><li>Like parameter visibility, it is common to transform local visibility to attribute visibility. For example, </li></ul><ul><ul><ul><ul><li>class Store { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>private ProductCatalog catalog; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>public Store() { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>ProductCatalog pc = new ProductCatalog(); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>… </li></ul></ul></ul></ul><ul><ul><ul><ul><li>catalog = pc; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} </li></ul></ul></ul></ul>
  11. 11. GLOBAL VISIBILITY <ul><li>Global visibility from A to B exists when B is global to A. </li></ul><ul><li>It is a relatively permanent visibility as it persists as long as A and B exist. </li></ul><ul><li>This is the least common form of visibility in object-oriented systems. </li></ul><ul><li>One way to achieve global visibility is to assign an object to a global variable. This is possible for languages like C++ but not for others, such as Java. </li></ul><ul><li>Another (much preferred) way to achieve global visibility is to apply the Singleton pattern. </li></ul>

×