| 1 | = Access Modifiers = |
| 2 | |
| 3 | Access Modifiers can be specified on Classes, Class (instance and class) variables and methods to set their visibility and accessibility |
| 4 | These are also called 'isNames' in the Cobra doc and Discussion since they're specified with a leading '''is''' keyword. |
| 5 | |
| 6 | Method Access modifiers |
| 7 | '''virtual, public''' is default for methods[[BR]] |
| 8 | |
| 9 | '''protected''' is default for class/instance variables with '''_''' prefix on name[[BR]] |
| 10 | '''public''' is default for variables without '''_''' prefix |
| 11 | |
| 12 | Valid 'is' keywords are |
| 13 | * '''fake''' - specifies item has no implementation - a placeholder |
| 14 | * '''shared''' - Specifies Class (static) method or variable, |
| 15 | * '''virtual''', '''nonvirtual''' - on methods, specifies that its overridable or not |
| 16 | * '''override''', '''new''' - on methods specifies that a method is overriding or replacing a baseclass method of same signature |
| 17 | * '''public''', '''protected''', '''private''', '''internal''' - specifies item visibility |
| 18 | * '''abstract''' - specifies a template only, subclasses must define |
| 19 | |
| 20 | Separate multiple by modifiers with ''',''' e.g .... is protected, override |
| 21 | |
| 22 | is fake:: |
| 23 | temporary for defining class/method api without implementation |
| 24 | e.g |
| 25 | {{{ |
| 26 | class TextWriter |
| 27 | is fake |
| 28 | |
| 29 | get newLine as String |
| 30 | pass |
| 31 | }}} |
| 32 | |
| 33 | is shared:: |
| 34 | on instance variable makes it a class variable |
| 35 | (same as static (in Java)) |
| 36 | |
| 37 | is public/protected/private:: |
| 38 | on class or method(s) |
| 39 | adjust visibility (default public) |
| 40 | |
| 41 | is abstract:: |
| 42 | on class or method(s) |
| 43 | Is a Template for subclasses to provide implementation of. |
| 44 | |
| 45 | is virtual:: |
| 46 | method is redefinable |
| 47 | |
| 48 | is nonvirtual:: |
| 49 | method is not redefinable |
| 50 | |
| 51 | is override:: |
| 52 | Specifies that this method implementation is a redefinition of an existing(shadowed virtual or abstract) method defined in a superclass |
| 53 | is new:: |
| 54 | Designate that this method is a new one that hides the one that would have |
| 55 | been inherited from a baseclass. |
| 56 | e.g |
| 57 | {{{ |
| 58 | class Vehicle |
| 59 | |
| 60 | def drive is nonvirtual |
| 61 | pass |
| 62 | |
| 63 | class Car inherits Vehicle |
| 64 | |
| 65 | def drive is new |
| 66 | pass |
| 67 | }}} |
| 68 | |
| 69 | When a method, property or indexer has the same name and type signature as a base member, |
| 70 | you must specify '''is override''' or specify '''is new''' |
| 71 | or use '''base.''' in the implementation (which is an implicit '''is override''') |