Changes between Version 5 and Version 6 of AccessModifiers
- Timestamp:
- 01/14/14 11:09:35 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AccessModifiers
v5 v6 1 1 = Access Modifiers = 2 2 3 Access Modifiers can be specified on Classes, class(instance and class) variables and methods to set their visibility and accessibility[[BR]]3 Access Modifiers can be specified on Classes, (instance and class) variables and methods to set their visibility and accessibility[[BR]] 4 4 These are also called 'isNames' in the Cobra doc and discussion since they're specified with a leading '''is''' keyword. 5 5 6 Method Access modifiers7 '''virtual, public''' is default for methods[[BR]]8 9 '''protected''' is default for methods and class/instance variables with '''_''' prefix on name[[BR]]10 '''private''' is default for methods and class/instance variables with '''_ _''' (double underscore) prefix on name[[BR]]11 '''public''' is default for variables without any '''_''' prefix12 6 13 7 Valid 'is' keywords are 14 8 * '''fake''' - specifies item has no implementation - a placeholder (deprecated in favor of '''extern''') 15 * '''shared''' - Specifies Class (static) method or variable, 9 * '''extern''' - item has no implementation and is defined elsewhere (outside a cobra file) (replaces/preferred to '''fake''') 10 * '''shared''' - Specifies a Class (static) method or variable, 16 11 * '''virtual''', '''nonvirtual''' - on methods, specifies that the method is overridable or not 17 12 * '''override''', '''new''' - on methods specifies that a method is overriding or replacing a baseclass method of the same signature 18 13 * '''public''', '''protected''', '''private''', '''internal''' - specifies item visibility 19 * '''abstract''' - specifies a template only, subclasses must define fully 20 * '''extern''' - item has no implementation and is defined elsewhere (outside a cobra file) 14 * '''abstract''' - specifies the class or method is a template only, subclasses must define fully 21 15 * '''partial''' - on class types - specifies that the type is defined across multiple files 22 16 * '''readonly''' specifies that a variable or field cannot be modified. 23 It must be initialised as early as possible and cannot have its value modified after.17 * It must be initialised as early as possible and cannot have its value modified after. 24 18 25 19 Separate multiple modifiers with ''',''' e.g .... is protected, override 20 21 '''protected''' is default for methods and class or instance variables with '''_''' prefix on name[[BR]] 22 '''private''' is default for methods and class or instance variables with '''_ _''' (double underscore) prefix on name[[BR]] 23 '''public''' is default for variables without any '''_''' prefix 24 25 26 27 == Class is-names == 28 classes and interfaces are '''public''' by default[[BR]] 29 30 * '''fake''' - specifies class has no implementation - a placeholder (deprecated in favor of '''extern''') 31 * '''extern''' - class has no implementation and is defined elsewhere (outside a cobra file) - replaces '''fake'''. 32 * '''shared''' - Specifies that the entire class is made of static methods and (class) variables, 33 * '''public''', '''protected''', '''private''', '''internal''' - specifies the class visibility (default is '''public''') 34 * '''abstract''' - specifies the class is a template only, subclasses must define fully 35 * '''partial''' - specifies that the type is defined across multiple files 36 37 == Method is-names == 38 methods are '''virtual, public''' by default[[BR]] 39 40 Methods prefixed with '''_''' on their names are '''protected''' by default[[BR]] 41 Methods prefixed with '''_ _''' (double underscore) on their names are '''private''' by default.[[BR]] 42 Methods with no underscore prefixes are '''public''' by default. 43 44 * '''fake''' - specifies method has no implementation - a placeholder (deprecated in favor of '''extern''') 45 * '''extern''' - method has no implementation and is defined elsewhere (outside a cobra file) (use instead of '''fake''') 46 * '''shared''' - Specifies a class (static) method, 47 * '''virtual''', '''nonvirtual''' - specifies that the method is overridable or not 48 * '''override''', '''new''' - specifies that a method is overriding or replacing a baseclass method of the same signature 49 * '''public''', '''protected''', '''private''', '''internal''' - specifies item visibility 50 * '''abstract''' - specifies the method is a template only, subclasses must define fully 51 52 == Type variables or fields is-names == 53 54 These are '''virtual, public''' by default[[BR]] 55 56 Type variables prefixed with '''_''' on their names are '''protected''' by default[[BR]] 57 Type variables prefixed with '''_ _''' (double underscore) on their names are '''private''' by default.[[BR]] 58 Type variables with no underscore prefixes are '''public''' by default. 59 60 * '''shared''' - Specifies a class (static) variable (rather than an instance variable), 61 * '''public''', '''protected''', '''private''', '''internal''' - specifies item visibility 62 * '''readonly''' specifies that a variable or field cannot be modified once initialised. 63 * It must be initialised as early as possible and cannot have its value modified after. 64 26 65 27 66 … … 30 69 31 70 Visibility (or accessibility) denotes the access to types or type variables (fields) 32 * public- the most permissive access level. There are no restrictions on accessing public members or public types.33 * protected- access is limited to the containing class or types derived from the containing class.34 * private- access is limited to the containing type.35 * internal- access is limited to the current assembly (or packaging entity).71 * '''public''' - the most permissive access level. There are no restrictions on accessing public members or public types. 72 * '''protected''' - access is limited to the containing class or types derived from the containing class. 73 * '''private''' - access is limited to the containing type. 74 * '''internal''' - access is limited to the current assembly (or packaging entity). 36 75 37 76 These modifiers cannot always map exactly as specified to backend supported visibility layers so best to treat them as decreasing … … 41 80 42 81 * is extern:: 43 - temporary for defining class/method apiwithout implementation82 - temporary for defining a class/method API without implementation 44 83 e.g 45 84 {{{ … … 52 91 53 92 * is shared:: 54 - on instance variable makes it a class variable.93 - on a variable/field of a type makes it a class variable. 55 94 - on method makes it a class method 56 95 - (effect is same as static (in C#, Java)) … … 64 103 65 104 * is public/protected/private/internal:: 66 - on class, instance variable or method(s)105 - on class, type variable or method(s) 67 106 - adjust visibility (default public) 68 107 … … 72 111 73 112 * is virtual:: 74 - method is redefinable/subclassable (default) 113 - on a method 114 - method is redefinable/subclassable (default) 75 115 76 116 * is nonvirtual:: 77 - method is not redefinable, cannot be subclassed. 117 - on a method 118 - method is not redefinable, cannot be redefined or overridden. 78 119 79 120 * is override:: 80 121 - on a method 81 - Specifies that this method implementation is a redefinition of an existing(shadowed virtual or abstract) method defined in a superclass122 - Specifies that this method implementation is a redefinition of an existing(shadowed virtual or abstract) method defined in a base (or ancestor) class 82 123 83 124 * is new:: 84 125 - on a method 85 - designate that this method is a new one that hides the one that would have126 - designate that this method is a new one that hides the one (nonvirtual) that would have 86 127 been inherited from a baseclass. 87 128 e.g … … 93 134 pass 94 135 136 def steer # virtual by default 137 95 138 class Car inherits Vehicle 96 139 97 140 def drive is new # replaces superclass method 98 141 pass 142 143 def steer is override # is override must be specified to indicate planned override of virtual baseclass method 99 144 }}} 100 145 … … 105 150 106 151 * is partial:: 107 - on class types ( 152 - on class types (class, structures, interfaces) 108 153 - indicates that the type is defined across multiple files. Each piece so defined must be so tagged. 109 - Idiomatically the first file compiled should have the full declaration (inheritance, attri nutes etc) and the remainder have only the access modifies ( including 'partial')154 - Idiomatically the first file compiled should have the full declaration (inheritance, attributes etc) and the remainder have only the access modifies ( including 'partial') 110 155 111 156 * is readonly::