Access control

Access modifiers

The open and closed keyword are access modifiers. Access modifiers determine the access level of a member.

If you specify the open keyword to a member definition, the member is open member. You can invoke the member at anywhere in the program.

If you specify the closed keyword to a member definition, the member is closed member. You can invoke the member only within the class definition which the member has been defined.

Default access level

A field is always closed. Therefore, an access modifier is unnecessary.

Other members do not have default access level. Therefore, you have to specify an access modifier at the beginning of the fitter, setter, getter, and method definition.

A class is always open. Therefore, an access modifier is unnecessary.

Encapsulation of the class level

Access control of the Rice is carried out at the class level. Namely, the definition of the class A can access the closed members of all instances of class A.


class sample

int _fi;

...

open setter Fi(sample val)

_fi = new int(val._fi); // ♦1

endsetter

...

endclass


♦1: The definition of the sample is possible to access to the closed members of the val because the val is the sample.

Copyright © Rice All rights reserved.