AnimationsTopHomework   LabPublic, Confidential, Readable, and Writable

Public, Confidential, Readable, and Writable

Declarations of items in a class or object that are public may be seen by code both inside and outside the class/object. Items that are marked confidential are accessible only inside the class/object (we'll see it is slightly more accessible when we discuss inherits in more detail).

Identifiers introduced via def and var are by default confidential. Methods are by default public. Can hide a method from outside objects by writing methd m(...) -> ... is confidential See example with laundry.

If we declare a def to be public, then the system automatically generates a new parameterless public method that returns the value. E.g., in homework, declaring def northPole: Pole is public = ... automatically provide the method northPole -> Pole called for in the type Magnet. This is very useful when we want to create helper methods so that we don't have to repeat the same code over and over.

Declaring a var to be public creates both "getter" and "setter" public methods for the variable. E.g.,

    var x:Number is public := 0

creates new public methods

     x -> Number
     x:=(newX:Number) -> Done

For a var definition we can be more selective and declare a var declaration to be readable or writable, which generate only one of the two methods.


AnimationsTopHomework   LabPublic, Confidential, Readable, and Writable