1 / 8

Object-Oriented Programming Encapsulation Control/ Visibility (VRH 7.3.3)

Object-Oriented Programming Encapsulation Control/ Visibility (VRH 7.3.3). Carlos Varela RPI Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL April 16, 2015. Controlling visibility.

rosellab
Download Presentation

Object-Oriented Programming Encapsulation Control/ Visibility (VRH 7.3.3)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object-OrientedProgrammingEncapsulation Control/Visibility (VRH 7.3.3) Carlos Varela RPI Adaptedwith permission from: SeifHaridi KTH Peter Van Roy UCL April 16, 2015 C. Varela; Adapted from S. Haridi and P. Van Roy

  2. Controlling visibility • Visibility is the control given to the user to limit access to members of a class (attributes, methods and properties) • Each member is defined with a scope (part of program text that the member can be accessed by name) • Programming languages use words like public, private and protected to define visibility • Unfortunately different languages use these keywords to define different scopes C. Varela; Adapted from S. Haridi and P. Van Roy

  3. Public and private scopes in ADTs • A private member is one which is only visible in the object instance (it is used for implementing the ADT) • The object instance can see all the private members in its class and its super classes • A public member is visible anywhere in the program • It is part of the interface of the ADT • In Oz (and Smalltalk) attributes are private and methods are public (the default rule) • In Java and C++ private has another meaning C. Varela; Adapted from S. Haridi and P. Van Roy

  4. The meaning of Private C Class Hierarchy SubC SubSubC I1 I2 I3 I4 Instances C. Varela; Adapted from S. Haridi and P. Van Roy

  5. The meaning of Private C Class Hierarchy According to Smalltalk and Oz SubC All private members in this region are visible to I3 SubSubC I1 I2 I3 I4 Instances C. Varela; Adapted from S. Haridi and P. Van Roy

  6. The meaning of Private C Class Hierarchy According to C++ and Java All private members in this region are visible to I3 SubC SubSubC I1 I2 I3 I4 Instances C. Varela; Adapted from S. Haridi and P. Van Roy

  7. Public and private scopes in ADTs • In Oz (and Smalltalk) attributes are private and methods are public • It is possible in Oz to make a method private within a class • Using a variable identifier as a method head will make the method local to the class • The variable is automatically bound to a unique name class C meth A(...) ... end .... end C. Varela; Adapted from S. Haridi and P. Van Roy

  8. Public and private scopes in ADTs • In Oz (and Smalltalk) attributes are private and methods are public • It is possible in Oz to make a method private within a class • Using a variable identifier as a method head will make the method local to the class • The variable is automatically bound to a unique name • ! is an escape character, !A means escape the class scope class C meth A(...) ... end .... end local A = {NewName} in class C meth!A(...) ... end .... end end C. Varela; Adapted from S. Haridi and P. Van Roy

More Related